Flutter:java.lang.NoClassDefFoundError:解析失败:Lcom/google/firebase/iid/FirebaseInstanceId

Posted

技术标签:

【中文标题】Flutter:java.lang.NoClassDefFoundError:解析失败:Lcom/google/firebase/iid/FirebaseInstanceId【英文标题】:Flutter: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId 【发布时间】:2021-09-20 00:53:28 【问题描述】:

SDK:颤振

我们在我们的应用中使用 Flutter 和 Firebase 消息传递。除此之外,我们还使用 plain_notification_token 来获取 android 的 FCM 令牌和 ios 的 APNS 令牌。将 Gradle 升级到 4.2.2 时出现此错误。

问题

E/AndroidRuntime(27480):    at net.kikuchy.plain_notification_token.PlainNotificationTokenPlugin.onMethodCall(PlainNotificationTokenPlugin.java:47)
E/AndroidRuntime(27480):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/AndroidRuntime(27480):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/AndroidRuntime(27480):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
E/AndroidRuntime(27480):    at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime(27480):    at android.os.MessageQueue.next(MessageQueue.java:335)
E/AndroidRuntime(27480):    at android.os.Looper.loop(Looper.java:183)
E/AndroidRuntime(27480):    at android.app.ActivityThread.main(ActivityThread.java:8010)
E/AndroidRuntime(27480):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(27480):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
E/AndroidRuntime(27480):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)
E/AndroidRuntime(27480): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId" on path: DexPathList[[zip file "/data/app/~~5gcFVfnQoOUOHN3V15pnZA==/money.bullet.internal-fy-pjwoLC9rHFRqMpeWWJw==/base.apk"],nativeLibraryDirectories=[/data/app/~~5gcFVfnQoOUOHN3V15pnZA==/money.bullet.internal-fy-pjwoLC9rHFRqMpeWWJw==/lib/arm64, /data/app/~~5gcFVfnQoOUOHN3V15pnZA==/money.bullet.internal-fy-pjwoLC9rHFRqMpeWWJw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64]]
E/AndroidRuntime(27480):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
E/AndroidRuntime(27480):    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(27480):    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(27480):    ... 11 more
I/Process (27480): Sending signal. PID: 27480 SIG: 9
Lost connection to device.

Android/app/build.gradle

dependencies 
    implementation fileTree(dir: "libs", include: ["*.jar", "*.aar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'androidx.core:core:1.6.0'
    implementation 'androidx.fragment:fragment:1.3.5'
    implementation "com.clevertap.android:clevertap-android-sdk:4.1.1"
    implementation 'com.google.android.play:core:1.10.0'
    implementation 'com.google.android.gms:play-services-basement:17.6.0'

    //MANDATORY for App Inbox
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'androidx.viewpager:viewpager:1.0.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'com.github.bumptech.glide:glide:4.11.0'

    //For CleverTap Android SDK v3.6.4 and above add the following -
    implementation 'com.android.installreferrer:installreferrer:2.2'

    //Optional ExoPlayer Libraries for Audio/Video Inbox Messages. Audio/Video messages will be dropped without these dependencies
    implementation 'com.google.android.exoplayer:exoplayer:2.14.1'
    implementation 'com.google.android.exoplayer:exoplayer-hls:2.14.1'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.14.1'
    implementation 'com.google.firebase:firebase-messaging:22.0.0'

    // For bureau-sdk to get the advertising-id
    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.1'
//    implementation 'com.google.firebase:firebase-iid'


apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf'

googleServices  disableVersionCheck = true 

这是 build.gradle 文件,在将 Gradle 版本从 3.x 更新到 4.2.2 后,Flutter 项目开始出现问题。我能够编译应用程序,但应用程序在运行时崩溃。

build.gradle

buildscript 
    ext.kotlin_version = '1.5.20'
    repositories 
        google()
        mavenCentral()
    

    dependencies 
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.8'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
        classpath 'com.google.firebase:perf-plugin:1.4.0'
    


allprojects 
    repositories 
        google()
        mavenCentral()
    
    configurations.all 
        resolutionStrategy 
            forcedModules = [
                    "com.google.android.gms:play-services-vision-common:19.0.2",
            ]
        
    


rootProject.buildDir = '../build'
subprojects 
    project.buildDir = "$rootProject.buildDir/$project.name"

subprojects 
    project.evaluationDependsOn(':app')


task clean(type: Delete) 
    delete rootProject.buildDir


【问题讨论】:

请查看此链接并仔细检查您的 Firebase / Google Play 服务依赖项以确保版本相互一致:***.com/a/42839972/421195 【参考方案1】:

添加

 implementation 'com.google.firebase:firebase-iid'

到您的 Android/app/build.gradle 应该可以解决问题。

【讨论】:

谢谢,我用这个解决方案解决了我的问题 这应该被标记为接受的答案 谢谢。这是我的情况的解决方案。 @Krutarth 请标记您的答案已接受。 :D

以上是关于Flutter:java.lang.NoClassDefFoundError:解析失败:Lcom/google/firebase/iid/FirebaseInstanceId的主要内容,如果未能解决你的问题,请参考以下文章

[Flutter] flutter项目一直卡在 Running Gradle task 'assembleDebug'...

flutter 日志输出,Flutter打印日志,flutter log,flutter 真机日志

Flutter开发 Flutter 包和插件 ( Flutter 包和插件简介 | 创建 Flutter 插件 | 创建 Dart 包 )

flutter与原生混编(iOS)

Flutter-布局

如何解决flutter gradle build error?C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991