java.lang.NoClassDefFoundError:无法解析:推送器 api 上的 Lcom/google/firebase/iid/FirebaseInstanceId
我想问如何解决这个问题,因为我尝试研究它,但是我在网上找到的答案都不适合我。我仍在注册该设备以在推送器网站上使用,当我复制此代码时,会弹出错误。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您使用的是 22.0 以上的
firebase:firebase-messaging
版本,您需要确保将这些行添加到您的应用程序 gradle来源。
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 gradleSource.
此问题已通过现已推出的以下版本得到解决:
如果需要,可以安全地更新这些依赖项并删除上述解决方法。请注意,建议使用 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:
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