java.lang.NoClassDefFoundError:无法解析:推送器 api 上的 Lcom/google/firebase/iid/FirebaseInstanceId

发布于 2025-01-17 06:49:12 字数 6178 浏览 2 评论 0原文

我想问如何解决这个问题,因为我尝试研究它,但是我在网上找到的答案都不适合我。我仍在注册该设备以在推送器网站上使用,当我复制此代码时,会弹出错误。

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

这是我的项目 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
} }

和我的应用程序 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'

,最后这是我的 java 类

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(); } }); }

,这是错误

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅渡 2025-01-24 06:49:12

由于您使用的是 22.0 以上的 firebase:firebase-messaging 版本,您需要确保将这些行添加到您的应用程序 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'

来源

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.

满地尘埃落定 2025-01-24 06:49:12

此问题已通过现已推出的以下版本得到解决:

com.google.firebase:firebase-crashlytics:18.3.5
com.google.firebase:firebase-crashlytics-ktx:18.3.5
com.google.firebase:firebase-crashlytics-ndk:18.3.5
com.google.firebase:firebase-installations:17.1.2
com.google.firebase:firebase-installations-ktx:17.1.2

如果需要,可以安全地更新这些依赖项并删除上述解决方法。请注意,建议使用 Firebase BoM 来控制 Firebase 库版本(最新的 BoM 是 v31.2.2)。

参考:
https://github.com/firebase/firebase-android- sdk/issues/4683#issuecomment-1432270489

This issue has been resolved with the following releases which are now live:

com.google.firebase:firebase-crashlytics:18.3.5
com.google.firebase:firebase-crashlytics-ktx:18.3.5
com.google.firebase:firebase-crashlytics-ndk:18.3.5
com.google.firebase:firebase-installations:17.1.2
com.google.firebase:firebase-installations-ktx:17.1.2

It is safe to update these dependencies and remove the above workarounds, if needed. Note that using the Firebase BoM is the recommended way to control Firebase library versions (the latest BoM is v31.2.2).

Reference:
https://github.com/firebase/firebase-android-sdk/issues/4683#issuecomment-1432270489

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文