Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to null-safety #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"appcenter","path":"/Users/marcinwroblewski/Documents/Projects/flutter/flutter_plugin_appcenter/src/appcenter/","native_build":true,"dependencies":[]},{"name":"appcenter_analytics","path":"/Users/marcinwroblewski/Documents/Projects/flutter/flutter_plugin_appcenter/src/appcenter_analytics/","native_build":true,"dependencies":[]},{"name":"appcenter_crashes","path":"/Users/marcinwroblewski/Documents/Projects/flutter/flutter_plugin_appcenter/src/appcenter_crashes/","native_build":true,"dependencies":[]}],"android":[{"name":"appcenter","path":"/Users/marcinwroblewski/Documents/Projects/flutter/flutter_plugin_appcenter/src/appcenter/","native_build":true,"dependencies":[]},{"name":"appcenter_analytics","path":"/Users/marcinwroblewski/Documents/Projects/flutter/flutter_plugin_appcenter/src/appcenter_analytics/","native_build":true,"dependencies":[]},{"name":"appcenter_crashes","path":"/Users/marcinwroblewski/Documents/Projects/flutter/flutter_plugin_appcenter/src/appcenter_crashes/","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"appcenter","dependencies":[]},{"name":"appcenter_analytics","dependencies":[]},{"name":"appcenter_crashes","dependencies":[]}],"date_created":"2023-08-19 23:41:03.045589","version":"3.3.10"}
13 changes: 6 additions & 7 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdk 33

lintOptions {
disable 'InvalidPackage'
Expand All @@ -26,10 +25,10 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.yourcompany.appcenterexample"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

buildTypes {
Expand All @@ -46,7 +45,7 @@ flutter {
}

dependencies {
androidTestImplementation 'com.android.support:support-annotations:25.4.0'
androidTestImplementation 'com.android.support.test:runner:0.5'
androidTestImplementation 'com.android.support.test:rules:0.5'
androidTestImplementation 'androidx.annotation:annotation:1.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
}
25 changes: 18 additions & 7 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="appcenter_example"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -22,14 +22,25 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->

<!-- Specify that the launch screen should continue being displayed -->
<!-- until Flutter renders its first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />

<!-- Theme to apply as soon as Flutter begins rendering frames -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>

<meta-data
android:name="flutterEmbedding"
android:value="2" />

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
package com.yourcompany.appcenterexample;

import android.os.Bundle;

import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity { }
5 changes: 5 additions & 0 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
9 changes: 5 additions & 4 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.android.tools.build:gradle:7.4.2'
}
}

allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
Expand All @@ -26,6 +27,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
2 changes: 2 additions & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-all.zip
10 changes: 5 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:appcenter/appcenter.dart';
import 'package:appcenter_analytics/appcenter_analytics.dart';
import 'package:appcenter_crashes/appcenter_crashes.dart';
import 'package:flutter/foundation.dart' show defaultTargetPlatform;
import 'package:flutter/foundation.dart' show TargetPlatform;

void main() => runApp(MyApp());

Expand All @@ -14,13 +12,15 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
String _appSecret;
late String _appSecret;
String _installId = 'Unknown';
bool _areAnalyticsEnabled = false, _areCrashesEnabled = false;

_MyAppState() {
final ios = defaultTargetPlatform == TargetPlatform.iOS;
_appSecret = ios ? "a8a33033-ef2f-4911-a664-a7d118287ce7" : "3f1f3b0e-24ff-436a-b42d-3c08b117d46a";
_appSecret = ios
? "a8a33033-ef2f-4911-a664-a7d118287ce7"
: "3f1f3b0e-24ff-436a-b42d-3c08b117d46a";
}

@override
Expand Down Expand Up @@ -61,7 +61,7 @@ class _MyAppState extends State<MyApp> {
Text('Install identifier:\n $_installId'),
Text('Analytics: $_areAnalyticsEnabled'),
Text('Crashes: $_areCrashesEnabled'),
RaisedButton(
ElevatedButton(
child: Text('Generate test crash'),
onPressed: AppCenterCrashes.generateTestCrash,
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: appcenter_example
description: Demonstrates how to use the appcenter plugin.

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
Expand Down
76 changes: 0 additions & 76 deletions publish.dart

This file was deleted.

13 changes: 6 additions & 7 deletions src/appcenter/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ version '1.0-SNAPSHOT'

buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.android.tools.build:gradle:7.4.2'
}
}

rootProject.allprojects {
repositories {
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
Expand All @@ -26,15 +26,14 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
buildToolsVersion '27.0.3'
compileSdk 33

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
lintOptions {
disable 'InvalidPackage'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-all.zip
1 change: 1 addition & 0 deletions src/appcenter/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.appcenter">
<meta-data android:name="flutterEmbedding" android:value="2"/>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
import java.util.UUID;
import java.util.List;
import java.util.ArrayList;

import android.app.Activity;
import android.app.Application;

import androidx.annotation.NonNull;

import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.utils.async.AppCenterConsumer;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
Expand All @@ -17,28 +24,42 @@
/**
* AppcenterPlugin
*/
public class AppcenterPlugin implements MethodCallHandler {
public class AppcenterPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware {

private MethodChannel channel;
private Activity activity;

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
channel = new MethodChannel(binding.getBinaryMessenger(), "aloisdeniel.github.com/flutter_plugin_appcenter/appcenter");
channel.setMethodCallHandler(this);
}

private Registrar registrar;
@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
channel.setMethodCallHandler(null);
}

@Override public void onDetachedFromActivity() {}

@Override public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) {
useBinding(binding);
}

private AppcenterPlugin(Registrar registrar) {
this.registrar = registrar;
@Override public void onAttachedToActivity(ActivityPluginBinding binding) {
useBinding(binding);
}

/**
* Plugin registration.
*/
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "aloisdeniel.github.com/flutter_plugin_appcenter/appcenter");
@Override public void onDetachedFromActivityForConfigChanges() {}

final AppcenterPlugin plugin = new AppcenterPlugin(registrar);
channel.setMethodCallHandler(plugin);
private void useBinding(ActivityPluginBinding binding) {
activity = binding.getActivity();
}

@Override
public void onMethodCall(MethodCall call, final Result result) {
public void onMethodCall(MethodCall call, @NonNull final Result result) {

Application app = this.registrar.activity().getApplication();
Application app = this.activity.getApplication();

switch (call.method) {
case "installId":
Expand Down
Loading