diff --git a/.gitignore b/.gitignore index 7ecebb4..95abf25 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ .packages .pub/ -pubspec.lock build/ + +# +*.iml +.idea/ diff --git a/android/build.gradle b/android/build.gradle index 54abd54..f0a3a98 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ group 'com.crazecoder.flutterbugly' -version '1.0-SNAPSHOT' +version '0.3.2+1' buildscript { repositories { @@ -8,7 +8,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.1' + classpath 'com.android.tools.build:gradle:4.1.0' } } diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index fccb353..7c60dc0 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,30 +1,4 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/android/src/main/java/com/crazecoder/flutterbugly/FlutterBuglyPlugin.java b/android/src/main/java/com/crazecoder/flutterbugly/FlutterBuglyPlugin.java index 6fa07b7..6eca0e2 100644 --- a/android/src/main/java/com/crazecoder/flutterbugly/FlutterBuglyPlugin.java +++ b/android/src/main/java/com/crazecoder/flutterbugly/FlutterBuglyPlugin.java @@ -1,10 +1,11 @@ package com.crazecoder.flutterbugly; -import android.annotation.SuppressLint; import android.app.Activity; +import android.content.Context; import android.text.TextUtils; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.crazecoder.flutterbugly.bean.BuglyInitResultInfo; import com.crazecoder.flutterbugly.utils.JsonUtil; @@ -22,6 +23,7 @@ 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.BinaryMessenger; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; @@ -31,25 +33,70 @@ /** * FlutterBuglyPlugin */ -public class FlutterBuglyPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware { +public class FlutterBuglyPlugin implements FlutterPlugin, ActivityAware, MethodCallHandler { + private MethodChannel channel; + private Context applicationContext; + private Activity activity; private Result result; private boolean isResultSubmitted = false; - private static MethodChannel channel; - @SuppressLint("StaticFieldLeak") - private static Activity activity; - private FlutterPluginBinding flutterPluginBinding; /** * Plugin registration. */ + @Deprecated public static void registerWith(Registrar registrar) { - channel = new MethodChannel(registrar.messenger(), "crazecoder/flutter_bugly"); - FlutterBuglyPlugin plugin = new FlutterBuglyPlugin(); - channel.setMethodCallHandler(plugin); - activity = registrar.activity(); + FlutterBuglyPlugin instance = new FlutterBuglyPlugin(); + instance.onAttachedToEngine(registrar.context(), registrar.activity(), registrar.messenger()); } + // + public void onAttachedToEngine(@NonNull Context applicationContext, @Nullable Activity activity, @NonNull BinaryMessenger messenger) { + channel = new MethodChannel(messenger, "crazecoder/flutter_bugly"); + channel.setMethodCallHandler(this); + this.applicationContext = applicationContext; + this.activity = activity; + } + + // --- FlutterPlugin + + @Override + public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { + onAttachedToEngine(binding.getApplicationContext(), null, binding.getBinaryMessenger()); + } + + @Override + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { + channel.setMethodCallHandler(null); + channel = null; + + applicationContext = null; + } + + // --- ActivityAware + + @Override + public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) { + activity = binding.getActivity(); + } + + @Override + public void onDetachedFromActivityForConfigChanges() { + onDetachedFromActivity(); + } + + @Override + public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) { + onAttachedToActivity(binding); + } + + @Override + public void onDetachedFromActivity() { + activity = null; + } + + // --- MethodCallHandler + @Override public void onMethodCall(final MethodCall call, @NonNull final Result result) { isResultSubmitted = false; @@ -97,14 +144,16 @@ public void onUpgrade(int ret, UpgradeInfo strategy, boolean isManual, boolean i } } : null; } - Beta.canShowUpgradeActs.add(activity.getClass()); + if (activity != null) { + Beta.canShowUpgradeActs.add(activity.getClass()); + } String appId = call.argument("appId").toString(); - Bugly.init(activity.getApplicationContext(), appId, BuildConfig.DEBUG); + Bugly.init(applicationContext, appId, BuildConfig.DEBUG); if (call.hasArgument("channel")) { String channel = call.argument("channel"); if (!TextUtils.isEmpty(channel)) - Bugly.setAppChannel(activity.getApplicationContext(), channel); + Bugly.setAppChannel(applicationContext, channel); } result(getResultBean(true, appId, "Bugly 初始化成功")); } else { @@ -113,21 +162,21 @@ public void onUpgrade(int ret, UpgradeInfo strategy, boolean isManual, boolean i } else if (call.method.equals("setUserId")) { if (call.hasArgument("userId")) { String userId = call.argument("userId"); - Bugly.setUserId(activity.getApplicationContext(), userId); + Bugly.setUserId(applicationContext, userId); } result(null); } else if (call.method.equals("setUserTag")) { if (call.hasArgument("userTag")) { Integer userTag = call.argument("userTag"); if (userTag != null) - Bugly.setUserTag(activity.getApplicationContext(), userTag); + Bugly.setUserTag(applicationContext, userTag); } result(null); } else if (call.method.equals("putUserData")) { if (call.hasArgument("key") && call.hasArgument("value")) { String userDataKey = call.argument("key"); String userDataValue = call.argument("value"); - Bugly.putUserData(activity.getApplicationContext(), userDataKey, userDataValue); + Bugly.putUserData(applicationContext, userDataKey, userDataValue); } result(null); } else if (call.method.equals("checkUpgrade")) { @@ -185,37 +234,4 @@ private BuglyInitResultInfo getResultBean(boolean isSuccess, String appId, Strin bean.setMessage(msg); return bean; } - - @Override - public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { - this.flutterPluginBinding = binding; - } - - @Override - public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - channel.setMethodCallHandler(null); - flutterPluginBinding = null; - } - - @Override - public void onAttachedToActivity(@NonNull ActivityPluginBinding binding) { - activity = binding.getActivity(); - channel = new MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "crazecoder/flutter_bugly"); - channel.setMethodCallHandler(this); - } - - @Override - public void onDetachedFromActivityForConfigChanges() { - - } - - @Override - public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) { - - } - - @Override - public void onDetachedFromActivity() { - - } } \ No newline at end of file diff --git a/example/.gitignore b/example/.gitignore index 47e0b4d..0fa6b67 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,6 +1,5 @@ # Miscellaneous *.class -*.lock *.log *.pyc *.swp @@ -16,56 +15,32 @@ *.iws .idea/ -# Visual Studio Code related -.vscode/ +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ # Flutter/Dart/Pub related **/doc/api/ +**/ios/Flutter/.last_build_id .dart_tool/ .flutter-plugins +.flutter-plugins-dependencies .packages .pub-cache/ .pub/ -build/ +/build/ -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java +# Web related +lib/generated_plugin_registrant.dart -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* +# Symbolication related +app.*.symbols -# Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/example/android/.gitignore b/example/android/.gitignore new file mode 100644 index 0000000..0a741cb --- /dev/null +++ b/example/android/.gitignore @@ -0,0 +1,11 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3c9d085 --- /dev/null +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip diff --git a/example/ios/.gitignore b/example/ios/.gitignore new file mode 100644 index 0000000..e96ef60 --- /dev/null +++ b/example/ios/.gitignore @@ -0,0 +1,32 @@ +*.mode1v3 +*.mode2v3 +*.moved-aside +*.pbxuser +*.perspectivev3 +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!default.mode1v3 +!default.mode2v3 +!default.pbxuser +!default.perspectivev3 diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock new file mode 100644 index 0000000..8807f90 --- /dev/null +++ b/example/ios/Podfile.lock @@ -0,0 +1,29 @@ +PODS: + - Bugly (2.5.90) + - Flutter (1.0.0) + - flutter_bugly (0.0.1): + - Bugly + - Flutter + +DEPENDENCIES: + - Flutter (from `Flutter`) + - flutter_bugly (from `.symlinks/plugins/flutter_bugly/ios`) + +SPEC REPOS: + trunk: + - Bugly + +EXTERNAL SOURCES: + Flutter: + :path: Flutter + flutter_bugly: + :path: ".symlinks/plugins/flutter_bugly/ios" + +SPEC CHECKSUMS: + Bugly: 88bc32c0acc6fef7b74d610f0319ee7560d6b9fe + Flutter: 0e3d915762c693b495b44d77113d4970485de6ec + flutter_bugly: c9800f4d5bc5bdc27ffdde3417a26ba44266e0c3 + +PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d + +COCOAPODS: 1.10.0 diff --git a/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/example/pubspec.lock b/example/pubspec.lock new file mode 100644 index 0000000..e0b5c66 --- /dev/null +++ b/example/pubspec.lock @@ -0,0 +1,161 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.6.1" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.15.0" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.3" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_bugly: + dependency: "direct dev" + description: + path: ".." + relative: true + source: path + version: "0.3.2+1" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + matcher: + dependency: transitive + description: + name: matcher + url: "https://pub.dartlang.org" + source: hosted + version: "0.12.10" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + path: + dependency: transitive + description: + name: path + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + url: "https://pub.dartlang.org" + source: hosted + version: "1.8.1" + stack_trace: + dependency: transitive + description: + name: stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "1.10.0" + stream_channel: + dependency: transitive + description: + name: stream_channel + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + string_scanner: + dependency: transitive + description: + name: string_scanner + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" +sdks: + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.12.0" diff --git a/ios/.gitignore b/ios/.gitignore index 710ec6c..aa479fd 100644 --- a/ios/.gitignore +++ b/ios/.gitignore @@ -34,3 +34,4 @@ Icon? .tags* /Flutter/Generated.xcconfig +/Flutter/flutter_export_environment.sh \ No newline at end of file diff --git a/ios/flutter_bugly.podspec b/ios/flutter_bugly.podspec index b7b84fc..7ca8359 100644 --- a/ios/flutter_bugly.podspec +++ b/ios/flutter_bugly.podspec @@ -3,10 +3,10 @@ # Pod::Spec.new do |s| s.name = 'flutter_bugly' - s.version = '0.0.1' - s.summary = 'A new Flutter bugly plugin.' + s.version = '0.3.2+1' + s.summary = 'Flutter plugin for Tencent Bugly.' s.description = <<-DESC -A new Flutter bugly plugin. +Flutter plugin for Tencent Bugly, Crash monitoring, Crash analysis, exception reporting, application update, data statistics, etc. DESC s.homepage = 'http://example.com' s.license = { :file => '../LICENSE' } diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..c6fc8fd --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,51 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" + collection: + dependency: transitive + description: + name: collection + url: "https://pub.dartlang.org" + source: hosted + version: "1.15.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + meta: + dependency: transitive + description: + name: meta + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + typed_data: + dependency: transitive + description: + name: typed_data + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.0" + vector_math: + dependency: transitive + description: + name: vector_math + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" +sdks: + dart: ">=2.12.0 <3.0.0" + flutter: ">=1.12.0"