简体   繁体   English

如何在 Flutter APK Build 中使用 Visual Studio AppCenter 处理“Cannot run with sound null safety”错误

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

I'm trying to add AppCenter to my application but I get build error:我正在尝试将 AppCenter 添加到我的应用程序中,但出现构建错误:

Error: Cannot run with sound null safety, because the following dependencies don't support null safety:错误:无法以健全的空安全运行,因为以下依赖项不支持空安全:

  • package:appcenter包:应用中心
  • package:appcenter_analytics包:appcenter_analytics
  • package:appcenter_crashes包:appcenter_crashes

For solutions, see https://dart.dev/go/unsound-null-safety有关解决方案,请参阅https://dart.dev/go/unsound-null-safety

FAILURE: Build failed with an exception. FAILURE:构建失败,出现异常。

I added auto-generated code from AppCenter to my ->app/build.gradle我从 AppCenter 中添加了自动生成的代码到我的 ->app/build.gradle

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

You cannot run your project with these dependencies with sound null safety.您不能在具有良好空安全性的情况下使用这些依赖项运行您的项目。 If you're sure that you won't be having any Null Pointer Exceptions, then run your project from the root directory with this command:如果您确定不会出现任何空指针异常,请使用以下命令从根目录运行您的项目:

flutter run --no-sound-null-safety

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.我们不应该在 main.dart 中导入 appcenter、appcenter_analytics appcenter_crashespackage(也不应该将它们导入到 pubspec.yaml 中)我们应该做的是覆盖 MainActivity.java 中的“onCreate”方法并在那里实现 appcenter。 You can find more details in my answer.您可以在我的回答中找到更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM