Flutter:与设备的连接丢失(生产应用程序)

7

在调试模式和应用上传到Play商店后,当我第一次打开应用时,它会崩溃。但是如果我再次打开它,那么一切都正常。

I/zygote64(11974): Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.messaging.FirebaseMessagingService>: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/base.apk!classes3.dex)
Lost connection to device.

D/AndroidRuntime(11974): Shutting down VM
E/AndroidRuntime(11974): FATAL EXCEPTION: main
E/AndroidRuntime(11974): Process: com.ved.mentor101app, PID: 11974
E/AndroidRuntime(11974): java.lang.RuntimeException: Unable to instantiate service io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/base.apk"],nativeLibraryDirectories=[/data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/lib/arm64, /data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]

E/AndroidRuntime(11974):    Caused by: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzb extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.ved.mentor101app-AbvtNHTF_HGKeS2lffOLiw==/base.apk!classes3.dex)
E/AndroidRuntime(11974):        ... 13 more
I/zygote64(11974): Do partial code cache collection, code=61KB, data=44KB
I/zygote64(11974): After code cache collection, code=61KB, data=44KB
I/zygote64(11974): Increasing code cache capacity to 256KB
I/Process (11974): Sending signal. PID: 11974 SIG: 9er

完整的调试语句(无法在文本中上传,因为StackOverflow不允许其长度):1/32/33/3
// flutter doctor -v:
flutter doctor -v
[√] Flutter (Channel stable, v1.2.2-pre.1, on Microsoft Windows [Version 10.0.15063], locale en-US)
    • Flutter version 1.2.2-pre.1 at C:\Users\Dell\flutter
    • Framework revision 03b53e0901 (7 weeks ago), 2019-04-20 19:15:26 +0530
    • Engine revision 3757390fa4
    • Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\Dell\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 33.4.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[√] VS Code (version 1.34.0)
    • VS Code at C:\Users\Dell\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.1.0

[√] Connected device (1 available)
    • RMX1801 • 8843cc23 • android-arm64 • Android 8.1.0 (API 27)

• No issues found!


  [1]: https://istack.dev59.com/ZcIaC.webp
  [2]: https://istack.dev59.com/NzpLH.webp
  [3]: https://istack.dev59.com/EnqNV.webp

我想指出你正在使用一个非常过时的Flutter版本,你应该更新它。目前稳定渠道上的最新版本是v1.5.4-hotfix.2 https://flutter.dev/docs/development/tools/sdk/releases 。你使用了哪个需要Firebase的包? - F-1
是的,我知道这一点,但我在Flutter源代码中进行了一些自定义更改以适应我的应用程序,升级可能会将它们删除,但我很快就会升级Flutter。关于你的问题,我有6-7个包,但firebase_analytics是在此错误发生之前添加到项目中的最后一个! - Raj Dhakad
你能检查一下你的Gradle吗?听起来你可能正在遇到引用/依赖问题。https://github.com/flutter/flutter/issues/23545#issuecomment-434041145 https://github.com/OneSignal/OneSignal-Android-SDK/issues/754 - F-1
1个回答

7

最终帮助解决问题的是:

在应用层级别的 build.gradle 文件中进行以下更改:

 defaultConfig {      
    
    minSdkVersion 23
    
}

在项目的级别上,添加 gradle.properties 文件。
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true

build.gradle 文件中添加。
dependencies {
    classpath 'com.android.tools.build:gradle:3.4.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.2.0'
}

你的gradle版本应该大于5

如果你不需要使用Kotlin支持,可以跳过Kotlin插件 别忘了运行 flutter clean 然后 flutter pub upgrade

这些更改帮助我防止了我的应用程序崩溃,它应该也能帮助你。


1
谢谢,将这些行添加到gradle.properties中解决了我的问题。你有什么想法为什么它会表现出这样的情况? - Syph
随着SDK的更新,一些代码会逐渐失效,社区不得不更改配置文件。但是我们使用的是早期版本构建的本地项目,因此会出现一些代码冲突和这种类型的行为。如果我们从头开始创建一个新项目,然后再实现功能,那么就会减少错误的发生。 - Abhishek Kumar
我正在使用相同的配置值,但应用程序在模拟器上崩溃,而在真实设备上却没有。 - yardstick17

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接