我只是将Firebase消息传递库15.0.2
更新为17.3.4
,并删除了google ads
的依赖关系,并在gradle中添加了implementation 'com.google.firebase:firebase-ads:17.0.0'
,然后出现以下错误
java.lang.NoSuchMethodError: No virtual method subscribeToTopic(Ljava/lang/String;)V in class Lcom/google/firebase/messaging/FirebaseMessaging; or its super classes (declaration of 'com.google.firebase.messaging.FirebaseMessaging' appears in /data/app/com.gpsspeedometer.digital-fdVbKShrYobAnb4WWX4dgA==/base.apk)
at com.nined.fcm.services.FcmFireBaseInstanceIDService$Companion.subscribeToTopic(FcmFireBaseInstanceIDService.kt:32)
at com.nined.fcm.services.FcmFireBaseInstanceIDService.onTokenRefresh(FcmFireBaseInstanceIDService.kt:20)
at com.google.firebase.iid.FirebaseInstanceIdService.zzd(Unknown Source:6)
at com.google.firebase.iid.zzg.run(Unknown Source:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6)
at java.lang.Thread.run(Thread.java:764)
这是 FcmFireBaseInstanceIDServic.class 代码
打开类FcmFireBaseInstanceIDService:FirebaseInstanceIdService(){
override fun onTokenRefresh() {
// Get updated InstanceID token.
val refreshedToken = FirebaseInstanceId.getInstance().token
if (BuildConfig.DEBUG) Log.d("Refreshed token: %s", refreshedToken)
subscribeToTopic()
}
companion object {
private const val RELEASE_TOPIC = "img_ads"
private const val DEBUG_TOPIC = "test_app"
fun subscribeToTopic(): Boolean {
try {
if (FirebaseInstanceId.getInstance() != null && FirebaseInstanceId.getInstance().id != null && !FirebaseInstanceId.getInstance().id.isEmpty()) {
if (BuildConfig.DEBUG)
FirebaseMessaging.getInstance().subscribeToTopic(DEBUG_TOPIC)
else {
FirebaseMessaging.getInstance().subscribeToTopic(RELEASE_TOPIC)
FirebaseMessaging.getInstance().unsubscribeFromTopic(DEBUG_TOPIC)
}
return true
}
return false
} catch (e: Exception) {
Log.e("FirebaseMessaging", e.toString())
return false
}
}
}
}
此行FirebaseMessaging.getInstance().subscribeToTopic(RELEASE_TOPIC)
上的错误点