Android Question Firebase SubscribeToTopic Error [Solved]

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

One of my Apps, the source code of which I had not touched for more than a year now is working fine.

Seeing that targetSdkVersion restriction from Google is nearing, today, I just recompiled the app with the latest B4A 8.30

Unfortunately my app is failing at the Firebase SubscribeToTopic(), whereas the Old APK is working fine.

I do not know whether something related to FireBase Messaging has changed during the last one year time or not.

Here is the error that I get when I run my application

** Service (starter) Start **
Starter Service Start
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
firebasemessaging_subscribetotopics (java line: 211)
java.lang.NoSuchMethodError: No virtual method subscribeToTopic(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/messaging/FirebaseMessaging; or its super classes (declaration of 'com.google.firebase.messaging.FirebaseMessaging' appears in /data/app/com.myappname.publicapp-GhwQILYp_jyaJYR4-N2f1Q==/base.apk:classes2.dex)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at com.myappname.publicapp.firebasemessaging._subscribetotopics(firebasemessaging.java:211)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1154)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

** Activity (main) Pause, UserClosed = false **

I already have the following Manifest Entries
B4X:
'The following are the new Manifest entried required from B4A 6 onwards for FireBase,GooglePlayServices, FCM Notification etc

'Always required when using Google Play Services or Firebase:
'************ Google Play Services Base ************
AddApplicationText(
   <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"/>
    <meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************

'Always required when using Firebase:
'************ Firebase Base ************
CreateResourceFromFile("google-services", "google-services.json")
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(com.google.android.c2dm.permission.RECEIVE)
AddPermission(${applicationId}.permission.C2D_MESSAGE)
AddManifestText( <permission android:name="${applicationId}.permission.C2D_MESSAGE"
  android:protectionLevel="signature" />)
AddApplicationText(
<receiver
  android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
  android:enabled="true">
  <intent-filter>
  <action android:name="com.google.android.gms.measurement.UPLOAD"/>
  </intent-filter>
  </receiver>

  <service
  android:name="com.google.android.gms.measurement.AppMeasurementService"
  android:enabled="true"
  android:exported="false"/>
   <provider
  android:authorities="${applicationId}.firebaseinitprovider"
  android:name="com.google.firebase.provider.FirebaseInitProvider"
  android:exported="false"
  android:initOrder="100" />
    <receiver
  android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
  android:enabled="true">
  <intent-filter>
  <action android:name="com.google.android.gms.measurement.UPLOAD"/>
  </intent-filter>
  </receiver>

  <service
  android:name="com.google.android.gms.measurement.AppMeasurementService"
  android:enabled="true"
  android:exported="false"/>
   <receiver
  android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
  android:exported="true"
  android:permission="com.google.android.c2dm.permission.SEND" >
  <intent-filter>
  <action android:name="com.google.android.c2dm.intent.RECEIVE" />
  <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
  <category android:name="${applicationId}" />
  </intent-filter>
  </receiver>
    <receiver
  android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
  android:exported="false" />


  <service
  android:name="com.google.firebase.iid.FirebaseInstanceIdService"
  android:exported="true">
  <intent-filter android:priority="-500">
  <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
  </intent-filter>
  </service>
)
'************ Firebase Base (end) ************

'Notifications / FCM (Firebase Cloud Messaging) / push messages
'************ Firebase Notifications ************
AddApplicationText(
    <service
  android:name="com.google.firebase.messaging.FirebaseMessagingService"
  android:exported="true">
  <intent-filter android:priority="-500">
  <action android:name="com.google.firebase.MESSAGING_EVENT" />
  </intent-filter>
  </service>
   <service android:name="anywheresoftware.b4a.objects.FirebaseNotificationsService">
     <intent-filter>
  <action android:name="com.google.firebase.MESSAGING_EVENT"/>
     </intent-filter>
   </service>
)
'************ Firebase Notifications (end)************


Any idea, what is causing this error ?

Any help will be appreciated
 

Anser

Well-Known Member
Licensed User
Longtime User
AS I am using B4A 8.30, as recommended by Erel in the post https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/ , I changed the Manifest Entries for Firebase as follows.
B4X:
'Always required when using Google Play Services or Firebase:
'************ Google Play Services Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)

'Always required when using Firebase:
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)

'Always required when using Firebase Notifications / Push messages
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)

Unfortunately, the error is still there
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
and you also updated the SDK to the newest files?
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
and you also updated the SDK to the newest files?
I updated the repositories from
com.google.firebase:firebase-messaging (Google Maven) 11.8.0
com.google.firebase:firebase-messaging-license (Google Maven) 11.8.0

to
com.google.firebase:firebase-messaging (Google Maven) 17.0.0
com.google.firebase:firebase-messaging-license (Google Maven) 12.0.1

Unfortunately, the same error
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
did you updated all recommended items?
Yes. I updated all the recommended items.

Now I on the process of installing the latest Android-28
Shall check whether that will eliminate the error and then update this thread regarding the status
 
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
Problem solved.

When I logged on to the FireBase Console it asked me to accept their new policies. (I believe t is their new GDPR policy) :) I accepted it and then my app started working fine. Its very long time since I logged in into the console.
I should have done this first, but never doubted as my old APK was working.

So with that this issue is resolved.
 
Upvote 0
Top