How to Handle "Cannot run with sound null safety" error with Visual Studio AppCenter in Flutter APK Build

Issue

I’m trying to add AppCenter to my application but I get build error:

Error: Cannot run with sound null safety, because the following
dependencies don’t support null safety:

  • package:appcenter
  • package:appcenter_analytics
  • package:appcenter_crashes

For solutions, see https://dart.dev/go/unsound-null-safety

FAILURE: Build failed with an exception.

I added auto-generated code from AppCenter to my ->app/build.gradle

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

Solution

Spending some hours in pain, I found my solution and post it here

We should not import appcenter, appcenter_analytics appcenter_crashespackage in main.dart (also not import them into pubspec.yaml)
What we should do is, override "onCreate" method in MainActivity.java and implement appcenter there.
You can find more details in my answer.

Answered By – Aurora

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *