android - Firebase 中没有静态方法 intoSet |在我尝试实现 firebase 数据库和推送通知时出错
问题描述
我在运行我的应用程序时使用了 firebase 数据库和 firebase 推送通知,它因 firebase 错误而崩溃
这是错误:
java.lang.NoSuchMethodError: No static method intoSet(Ljava/lang/Object;Ljava/lang/Class;)Lcom/google/firebase/components/Component;in class Lcom/google/firebase/components/Component;or its super classes (declaration of 'com.google.firebase.components.Component' appears in /data/app/com.shadow.recipeworld-1/base.apk)
at com.google.firebase.platforminfo.LibraryVersionComponent.create(com.google.firebase:firebase-common@@19.3.0:25)
at com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar.getComponents(com.google.android.gms:play-services-measurement-api@@17.2.2:10)
at com.google.firebase.components.zzf.<init>(com.google.firebase:firebase-common@@16.0.2:52)
at com.google.firebase.FirebaseApp.<init>(com.google.firebase:firebase-common@@16.0.2:539)
at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:355)
at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:324)
at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@16.0.2:310)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@16.0.2:53)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@16.0.2:47)
at android.app.ActivityThread.installProvider(ActivityThread.java:5173)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4768)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4708)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1406)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5438)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:762)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
以下是gradle中的内容:
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.google.firebase:firebase-core:17.2.2'
implementation 'com.firebase:firebase-client-android:2.5.2'
我的通知服务:
public class GeneralNotificationService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Global.showNotification(getBaseContext(),remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());
}
}
我的通知功能:
public static void showNotification( Context c,String title,String message)
{
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O)
{
NotificationChannel channel =new NotificationChannel("GeneralNotification","GeneralNotification", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager=c.getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
Notification.Builder builder=new Notification.Builder(c,"GeneralNotification")
.setContentTitle(title)
.setSmallIcon(R.drawable.ic_launcher_background)
.setAutoCancel(true)
.setContentText(message);
manager.notify(1,builder.build());
}
else
{
NotificationCompat.Builder builder=new NotificationCompat.Builder(c,"GeneralNotification")
.setContentTitle(title)
.setSmallIcon(R.drawable.ic_launcher_background)
.setAutoCancel(true)
.setContentText(message);
NotificationManagerCompat manager=NotificationManagerCompat.from(c);
manager.notify(1,builder.build());
}
}
任何帮助将不胜感激!
解决方案
删除以下依赖项:
implementation 'com.firebase:firebase-client-android:2.5.2'
这是不再支持的旧 firebase 库。
推荐阅读
- php - 如果所有这些单词都与 PHP 中的 SQlite3 查询匹配,则排除结果
- python - 在python中将HTML表格转换为终端上的表格
- javascript - 如果达到限制,使用验证来防止用户添加到数据库
- javascript - NodeJS异步操作未在同步操作执行之前的初始执行中完成
- mysql - 将昂贵函数调用的结果存储在 MySQL 表中
- graphql - 固定长度的 GraphQL 列表
- python - 由于相关字段的 __str__ 方法,Django Admin Change View 卡住了
- python - 为什么没有在 PySpark 中分配值?
- java - 如何在输入空输入时跳出循环
- docker - Azure 启用内容信任会影响注册表中的现有图像吗?