diff --git a/flutter_appcenter_bundle/CHANGELOG.md b/flutter_appcenter_bundle/CHANGELOG.md index c438719..ffdb36f 100644 --- a/flutter_appcenter_bundle/CHANGELOG.md +++ b/flutter_appcenter_bundle/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.3.3 + +- Upgrade native AppCenter SDK to 4.4.1 (Change Logs: [Android](https://github.com/microsoft/appcenter-sdk-android/releases/tag/4.4.1) / [IOS](https://github.com/microsoft/appcenter-sdk-apple/releases/tag/4.4.1)) +- Support for AppCenter trackError #26 + ## 3.3.2 - Update Android deps diff --git a/flutter_appcenter_bundle/android/build.gradle b/flutter_appcenter_bundle/android/build.gradle index 899e551..09b1ee7 100644 --- a/flutter_appcenter_bundle/android/build.gradle +++ b/flutter_appcenter_bundle/android/build.gradle @@ -54,7 +54,7 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - def appCenterSdkVersion = '4.2.0' + def appCenterSdkVersion = '4.4.1' implementation "com.microsoft.appcenter:appcenter-analytics:$appCenterSdkVersion" implementation "com.microsoft.appcenter:appcenter-crashes:$appCenterSdkVersion" appCenterImplementation "com.microsoft.appcenter:appcenter-distribute:${appCenterSdkVersion}" diff --git a/flutter_appcenter_bundle/android/src/main/kotlin/com/github/hanabi1224/flutter_appcenter_bundle/FlutterAppcenterBundlePlugin.kt b/flutter_appcenter_bundle/android/src/main/kotlin/com/github/hanabi1224/flutter_appcenter_bundle/FlutterAppcenterBundlePlugin.kt index 065ae9c..51d3d04 100644 --- a/flutter_appcenter_bundle/android/src/main/kotlin/com/github/hanabi1224/flutter_appcenter_bundle/FlutterAppcenterBundlePlugin.kt +++ b/flutter_appcenter_bundle/android/src/main/kotlin/com/github/hanabi1224/flutter_appcenter_bundle/FlutterAppcenterBundlePlugin.kt @@ -6,6 +6,7 @@ import androidx.annotation.NonNull import com.microsoft.appcenter.AppCenter import com.microsoft.appcenter.analytics.Analytics import com.microsoft.appcenter.crashes.Crashes +import com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog import com.microsoft.appcenter.distribute.Distribute import com.microsoft.appcenter.distribute.UpdateTrack import io.flutter.embedding.engine.plugins.FlutterPlugin @@ -78,6 +79,18 @@ class FlutterAppcenterBundlePlugin : FlutterPlugin, MethodCallHandler, ActivityA val properties = call.argument>("properties") Analytics.trackEvent(name, properties) } + "trackError" -> { + val message = call.argument("message") + val properties = call.argument>("properties") + val stack = call.argument("stack") + val exception = Exception(message) + // exception.setStackTrace(); + Crashes.trackError( + exception, + properties, + stack?.let { listOf(ErrorAttachmentLog.attachmentWithText(stack, "stack.txt")) } + ) + } "isDistributeEnabled" -> { result.success(Distribute.isEnabled().get()) return diff --git a/flutter_appcenter_bundle/example/lib/main.dart b/flutter_appcenter_bundle/example/lib/main.dart index 0d8c53e..ef64305 100644 --- a/flutter_appcenter_bundle/example/lib/main.dart +++ b/flutter_appcenter_bundle/example/lib/main.dart @@ -1,18 +1,24 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:package_info/package_info.dart'; import 'package:flutter_appcenter_bundle/flutter_appcenter_bundle.dart'; void main() async { - WidgetsFlutterBinding.ensureInitialized(); - await AppCenter.startAsync( - appSecretAndroid: '49361c2e-b788-4bc2-a33d-838b04b3e06b', - appSecretIOS: '2da3d93f-6b3f-48f9-920f-2d63ae3cd25a', - enableDistribute: false, - ); - await AppCenter.configureDistributeDebugAsync(enabled: false); - - runApp(MyApp()); + runZonedGuarded>(() async { + WidgetsFlutterBinding.ensureInitialized(); + await AppCenter.startAsync( + appSecretAndroid: '49361c2e-b788-4bc2-a33d-838b04b3e06b', + appSecretIOS: '2da3d93f-6b3f-48f9-920f-2d63ae3cd25a', + enableDistribute: false, + ); + await AppCenter.configureDistributeDebugAsync(enabled: false); + + runApp(MyApp()); + }, (Object error, StackTrace stack) { + AppCenter.trackErrorAsync(error.toString(), stack); + }); } class MyApp extends StatefulWidget { diff --git a/flutter_appcenter_bundle/ios/Classes/SwiftFlutterAppcenterBundlePlugin.swift b/flutter_appcenter_bundle/ios/Classes/SwiftFlutterAppcenterBundlePlugin.swift index e8016c0..3ce69fd 100644 --- a/flutter_appcenter_bundle/ios/Classes/SwiftFlutterAppcenterBundlePlugin.swift +++ b/flutter_appcenter_bundle/ios/Classes/SwiftFlutterAppcenterBundlePlugin.swift @@ -6,20 +6,25 @@ import AppCenterAnalytics import AppCenterCrashes import AppCenterDistribute +typealias MSAppCenter = AppCenter +typealias MSAnalytics = Analytics +typealias MSCrashes = Crashes +typealias MSDistribute = Distribute + public class SwiftFlutterAppcenterBundlePlugin: NSObject, FlutterPlugin { static let methodChannelName = "com.github.hanabi1224.flutter_appcenter_bundle"; static let instance = SwiftFlutterAppcenterBundlePlugin(); - + public static func register(binaryMessenger: FlutterBinaryMessenger) -> FlutterMethodChannel { let methodChannel = FlutterMethodChannel(name: methodChannelName, binaryMessenger: binaryMessenger) methodChannel.setMethodCallHandler(instance.methodChannelHandler); return methodChannel; } - + public static func register(with registrar: FlutterPluginRegistrar) { register(binaryMessenger: registrar.messenger()); } - + public func methodChannelHandler(_ call: FlutterMethodCall, result: @escaping FlutterResult) { debugPrint(call.method) switch call.method { @@ -35,7 +40,7 @@ public class SwiftFlutterAppcenterBundlePlugin: NSObject, FlutterPlugin { MSDistribute.updateTrack = .private } - MSAppCenter.start(secret, withServices:[ + MSAppCenter.start(withAppSecret: secret, services:[ MSAnalytics.self, MSCrashes.self, MSDistribute.self, @@ -43,14 +48,23 @@ public class SwiftFlutterAppcenterBundlePlugin: NSObject, FlutterPlugin { case "trackEvent": trackEvent(call: call, result: result) return + case "trackError": + let args: [String: Any]? = (call.arguments as? [String: Any]) + Crashes.trackError( + NSError(domain: Bundle.main.bundleIdentifier ?? "", + code: -1, + userInfo: [NSLocalizedDescriptionKey: args?["message"] ?? ""]), + properties: args?["properties"] as? [String: String], + attachments: nil + ) + return case "isDistributeEnabled": - result(MSDistribute.isEnabled()) + result(MSDistribute.enabled) return case "getInstallId": - result(MSAppCenter.installId().uuidString) - return + result(MSAppCenter.installId.uuidString) case "configureDistribute": - MSDistribute.setEnabled(call.arguments as! Bool) + MSDistribute.enabled = call.arguments as! Bool case "configureDistributeDebug": result(nil) return @@ -58,36 +72,36 @@ public class SwiftFlutterAppcenterBundlePlugin: NSObject, FlutterPlugin { MSDistribute.disableAutomaticCheckForUpdate() case "checkForUpdate": MSDistribute.checkForUpdate() - case "isCrashesEnabled": - result(MSCrashes.isEnabled()) return + case "isCrashesEnabled": + result(MSCrashes.enabled) case "configureCrashes": - MSCrashes.setEnabled(call.arguments as! Bool) - case "isAnalyticsEnabled": - result(MSAnalytics.isEnabled()) + MSCrashes.enabled = call.arguments as! Bool return + case "isAnalyticsEnabled": + result(MSAnalytics.enabled) case "configureAnalytics": - MSAnalytics.setEnabled(call.arguments as! Bool) + MSAnalytics.enabled = call.arguments as! Bool default: result(FlutterMethodNotImplemented); return } - + result(nil); } - + private func trackEvent(call: FlutterMethodCall, result: FlutterResult) { guard let args:[String: Any] = (call.arguments as? [String: Any]) else { result(FlutterError(code: "400", message: "Bad arguments", details: "iOS could not recognize flutter arguments in method: (trackEvent)") ) return } - + let name = args["name"] as? String let properties = args["properties"] as? [String: String] if(name != nil) { MSAnalytics.trackEvent(name!, withProperties: properties) } - + result(nil) } } diff --git a/flutter_appcenter_bundle/ios/flutter_appcenter_bundle.podspec b/flutter_appcenter_bundle/ios/flutter_appcenter_bundle.podspec index 76181ea..22f96d5 100644 --- a/flutter_appcenter_bundle/ios/flutter_appcenter_bundle.podspec +++ b/flutter_appcenter_bundle/ios/flutter_appcenter_bundle.podspec @@ -14,8 +14,8 @@ A new flutter plugin project. s.author = { 'Your Company' => 'email@example.com' } s.source = { :path => '.' } s.source_files = 'Classes/**/*' - s.dependency 'AppCenter', '~> 3.3.4' - s.dependency 'AppCenter/Distribute', '~> 3.3.4' + s.dependency 'AppCenter', '~> 4.4.1' + s.dependency 'AppCenter/Distribute', '~> 4.4.1' s.dependency 'Flutter' s.platform = :ios, '8.0' s.static_framework = true diff --git a/flutter_appcenter_bundle/lib/flutter_appcenter_bundle.dart b/flutter_appcenter_bundle/lib/flutter_appcenter_bundle.dart index df65bfa..2505e0e 100644 --- a/flutter_appcenter_bundle/lib/flutter_appcenter_bundle.dart +++ b/flutter_appcenter_bundle/lib/flutter_appcenter_bundle.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:stack_trace/stack_trace.dart'; final _methodChannelName = 'com.github.hanabi1224.flutter_appcenter_bundle'; final _methodChannel = MethodChannel(_methodChannelName); @@ -57,6 +58,16 @@ class AppCenter { }); } + /// Track error + static Future trackErrorAsync(String message, StackTrace? stackTrace, + [Map? properties]) async { + await _methodChannel.invokeMethod('trackError', { + 'message': message, + 'properties': properties, + 'stack': stackTrace.toString() + }); + } + /// Check whether analytics is enalbed static Future isAnalyticsEnabledAsync() async { return await _methodChannel.invokeMethod('isAnalyticsEnabled'); diff --git a/flutter_appcenter_bundle/pubspec.yaml b/flutter_appcenter_bundle/pubspec.yaml index d7182a5..cd09751 100644 --- a/flutter_appcenter_bundle/pubspec.yaml +++ b/flutter_appcenter_bundle/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_appcenter_bundle description: This plugin currently bundles AppCenter Analytics, Crashes and Distribute. To learn more about AppCenter, go to https://aka.ms/appcenterdocs -version: 3.3.2 +version: 3.3.3 homepage: https://github.com/hanabi1224/flutter_appcenter_bundle publish_to: https://pub.dev/