Flutter: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId
Add
implementation 'com.google.firebase:firebase-iid'
to your Android/app/build.gradle and that should fix the issue.
Krutarth Dave
A passionate Software Engineer who choose this field because of my love for Computers, Mathematics, and Numbers. I excel at building consumer mobile apps with React Native/ Flutter and scalable web apps using React, Typescript, and everything in between. I believe in Clean Code and Pixel Perfect Design.
Updated on December 30, 2022Comments
-
Krutarth Dave over 1 year
SDK: Flutter
We are using Flutter with Firebase messaging in our app. Along with it, we are using plain_notification_token to get the FCM Token for Android and APNS Token for iOS. Getting this error when upgrading Gradle to 4.2.2.
Issue
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 }
This is the build.gradle file where after updating the Gradle version to 4.2.2 from 3.x, the issue started coming up in Flutter project. I am able to compile the App but the App crashes at Runtime.
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 }
-
paulsm4 almost 3 yearsPlease look at this link and double-check your Firebase / Google Play services dependencies to ensure the versions are all mutually consistent: stackoverflow.com/a/42839972/421195
-
-
awshakam98 over 2 yearsThank you, I solved my problem with this solution
-
luis over 2 yearsThis should be marked as the accepted answer
-
Ilham Safeek over 2 yearsThanks. this is the solution for my case.
-
Ishita Sinha over 2 years@Krutarth Please mark your answer accepted. :D