Firebase Error: java.lang.NoSuchMethodError: No virtual method subscribeToTopic(Ljava/lang/String;)V in class Lcom/google/firebase/messaging/

Viewed 654

I just update the firebase messaging library 15.0.2 to 17.3.4 and remove the google ads dependence and add the implementation 'com.google.firebase:firebase-ads:17.0.0' in gradle then I have following error

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)

Here is FcmFireBaseInstanceIDServic.class code

open 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
        }
    }
}

}

The error point on this line FirebaseMessaging.getInstance().subscribeToTopic(RELEASE_TOPIC)

0 Answers
Related