gpt4 book ai didi

java - 未找到类 "com.google.firebase.iid.FirebaseInstanceIdReceiver"

转载 作者:行者123 更新时间:2023-12-02 09:31:46 27 4
gpt4 key购买 nike

我想通过 firebase 发送通知。当我发送通知时,我的应用程序崩溃,在 logcat 中显示这种类型的堆栈跟踪:

 java.lang.RuntimeException: Unable to instantiate receiver com.google.firebase.iid.FirebaseInstanceIdReceiver: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceIdReceiver" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.e_agriculture10-1.apk", zip file "/data/data/com.example.e_agriculture10/code_cache/secondary-dexes/com.example.e_agriculture10-1.apk.classes2.zip"],nativeLibraryDirectories=[/data/app-lib/com.example.e_agriculture10-1, /system/lib]]
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2398)
at android.app.ActivityThread.access$1700(ActivityThread.java:135)

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceIdReceiver" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.example.e_agriculture10-1.apk", zip file "/data/data/com.example.e_agriculture10/code_cache/secondary-dexes/com.example.e_agriculture10-1.apk.classes2.zip"],nativeLibraryDirectories=[/data/app-lib/com.example.e_agriculture10-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)

这是我的 FirebaseMessagingService.java 类

public class MyFirebaseMessagingService extends FirebaseMessagingService {

public static int NOTIFICATION_ID = 1;
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

generateNotification(remoteMessage.getNotification().getBody(),remoteMessage.getNotification().getTitle());

}

private void generateNotification(String body, String title) {
Intent intent = new Intent(this,NotificationFragment.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.agriculture_home )
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true)
.setSound(soundUri)
.setContentIntent(pendingIntent);


NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
if (NOTIFICATION_ID > 1073741824){
NOTIFICATION_ID = 0;
}
notificationManager.notify(NOTIFICATION_ID++,notificationBuilder.build());


}
}

这是我的 GettingDeviceTokenService.java 文件:

public class GettingDeviceTokenService extends  FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
String DeviceToken = FirebaseInstanceId.getInstance().getToken();
Log.d("DEVICE TOKEN",DeviceToken);

}
}

这是我的 build.gradle(模块应用程序)

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.e_agriculture10"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-database:16.0.4'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'


implementation 'com.google.android.material:material:1.1.0-alpha9'

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.android.support:cardview-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation files('libs/YouTubeAndroidPlayerApi.jar')
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.firebase:firebase-client-android:2.5.2'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha09'

}

我怎样才能摆脱这个错误,请任何人指导我。提前致谢。

最佳答案

您可以删除此类“GettingDeviceTokenService”并覆盖“MyFirebaseMessagingService”类中的“onNewToken”方法。

public void onNewToken(@NonNull String your_new_token) {super.onNewToken(s);}

按照您的意愿使用新 token

关于java - 未找到类 "com.google.firebase.iid.FirebaseInstanceIdReceiver",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57904031/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com