Home > Software engineering >  java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId on
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId on

Time:03-29

I would like to ask how to fix this because I tried researching it but, none of the answers I found on the web worked for me. I'm still registering the device for use on the pusher website and when I copy this code the error pop up.

PushNotifications.start(getApplicationContext(), "mykey"); PushNotifications.addDeviceInterest("hello");

Here is my project Gradle

buildscript {
repositories {
    google()
    mavenCentral()
}
dependencies {
    classpath "com.android.tools.build:gradle:7.0.3"
    classpath 'com.google.gms:google-services:4.3.10'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
} }

And my app Gradle

dependencies {

implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.google.firebase:firebase-analytics:20.0.0'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation 'com.google.firebase:firebase-storage:20.0.0'
implementation 'com.google.firebase:firebase-messaging:23.0.0'
implementation 'com.google.firebase:firebase-core:17.4.4'
implementation 'com.pusher:push-notifications-android:1.6.2'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation "androidx.cardview:cardview:1.0.0"
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
testImplementation 'junit:junit:4. '
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'} apply plugin: 'com.google.gms.google-services'

and lastly here's my java class

public class Sprinkler extends AppCompatActivity {

Button On;
Button Off;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sprinkler);

    PushNotifications.start(getApplicationContext(), "mykey");
    PushNotifications.addDeviceInterest("hello");

    On = (Button) findViewById(R.id.switch1);
    Off = (Button) findViewById(R.id.switch2);
    On.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // getting the default FirebaseDatabase instance
            FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();

            // getting a DatabaseReference for the database root node
            DatabaseReference databaseReference = firebaseDatabase.getReference("Relay_Status");

            databaseReference.setValue(1);

            Toast.makeText(getApplicationContext(), "Sprinkler Turn On!", Toast.LENGTH_SHORT).show(); } }); }

and here's the error

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.fire_app, PID: 24128
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/iid/FirebaseInstanceId;
    at com.pusher.pushnotifications.PushNotificationsInstance.start(PushNotificationsInstance.kt:180)
    at com.pusher.pushnotifications.PushNotifications.start(PushNotifications.java:31)
    at com.example.fire_app.Sprinkler.onCreate(Sprinkler.java:27)
    at android.app.Activity.performCreate(Activity.java:5990)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId" on path: DexPathList[[zip file "/data/app/com.example.fire_app-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    at com.pusher.pushnotifications.PushNotificationsInstance.start(PushNotificationsInstance.kt:180) 
    at com.pusher.pushnotifications.PushNotifications.start(PushNotifications.java:31) 
    at com.example.fire_app.Sprinkler.onCreate(Sprinkler.java:27) 
    at android.app.Activity.performCreate(Activity.java:5990) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
    at android.app.ActivityThread.access$800(ActivityThread.java:151) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:135) 
    at android.app.ActivityThread.main(ActivityThread.java:5254) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:372) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
    Suppressed: java.lang.ClassNotFoundException: com.google.firebase.iid.FirebaseInstanceId
    at java.lang.Class.classForName(Native Method)
    at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
            ... 17 more
 Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

CodePudding user response:

As you are using a firebase:firebase-messaging version above 22.0 you will need to ensure you also add these lines to your app gradle

implementation "com.google.firebase:firebase-iid:21.1.0"
implementation 'com.pusher:push-notifications-android:1.9.0'

// Add this line to the end of the file
apply plugin: 'com.google.gms.google-services'

Source.

  • Related