Visual Studio App Center with Flutter App

Viewed 1999

I have an app I created using Flutter / Dart / VSCode / Android Studio and wanted to work on it with Visual Studio App Center.

I add an Android app using Java / Kotlin, then add

dependencies { def appCenterSdkVersion = '3.2.2' implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}" implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}" }

to app/build.gradle but that's about as far as I get before messing up.

I don't know what 'my app's main class activity' is, I'm guessing it's not main.dart as when I put the following code in there I get errors.

import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.analytics.Analytics;
import com.microsoft.appcenter.crashes.Crashes;

I also can't find onCreate anywhere (other than AndroidManifest.xml where it's commented out).

I've looked through Getting started with the Android SDK, but can't figure it out.

Can anyone help me out?

I'm pretty much at the end of my tether so any help would be greatly appreciated!

UPDATE

build.gradle

dependencies {
    def appCenterSdkVersion = '3.2.2'
    implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
    implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
}

MainActivity.kt

import com.microsoft.appcenter.AppCenter;
import com.microsoft.appcenter.analytics.Analytics;
import com.microsoft.appcenter.crashes.Crashes;

AndroidManifest.xml

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
AppCenter.start(getApplication(), "{My App Secret}",
                  Analytics.class, Crashes.class);
1 Answers

If you want to catch the crashes from Flutter there might be bit tricky for you because technically you'll have 4 types of crashes.

  1. Android native crash.
  2. iOS Native crash.
  3. Dart crash
  4. Flutter/Dart errors (i know they are not actual crashes but might mess up the app).

Now for point 1, if you want to add AppCenter you can add the code in the onCreate method of the FlutterApplication. You can find it your project -> android -> app -> src -> main -> expand packages

For iOS Native crash you will have to do it in AppDelegate, which is in your project -> iOS -> Runner -> AppDelegate.

For Dart/Flutter crash errors, I don't think there is support from AppCenter. I personally use Sentry and it's doing a pretty good job.

Related