Android Question Error Firebase with B4A V8

Marcos Alves

Well-Known Member
Licensed User
Hi,

I'm trying to compile an apk using B4A V8 and got the 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.comten.nexphone-2/base.apk)

The compilation was running without any error in B4A V7... what's wrong?

Like recommended, I added the lines to Manifest:

CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile("google-services", "google-services.json")

Doesn't work either :( . I'm seriously thinking to do a downgrade to B4A 7...
 
Last edited:

DonManfred

Expert
Licensed User
using B4A V8
Like recommended, I added the lines to Manifest:

CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile("google-services", "google-services.json")
Go again over the tutorial and do it the right way
https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/

I just tried a project of mine and used an updated sdk. It does work here as expected.
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Go again over the tutorial and do it the right way
https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/

I just tried a project of mine and used an updated sdk. It does work here as expected.
Hello,

let me try to be clear:

1. I have an apk published and 100% functional running on Google Play Store, compiled with Firebase and B4A V7 ...

2. I upgraded to B4A V8... then, added to the Manifest, as oriented in tutorial:

CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)

3. The line above and json was already referenced in V7 at the same way:

CreateResourceFromFile("google-services", "google-services.json")

4. Compiled fine with B4A V8, but when running:

Initialize_Voip
** Activity (main) Pause, UserClosed = true **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
** Service (firebasemessaging) Start **
** Service (firebasemessaging) Start **
** Activity (dialpad) Create, isFirst = true **
** Activity (dialpad) Resume **
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 /mnt/asec/com.comten.nexphone-45/base.apk)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at com.comten.nexphone.firebasemessaging._subscribeindividual(firebasemessaging.java:1527)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
java.lang.RuntimeException: 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 /mnt/asec/com.comten.nexphone-45/base.apk)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:170)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: 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 /mnt/asec/com.comten.nexphone-45/base.apk)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at com.comten.nexphone.firebasemessaging._subscribeindividual(firebasemessaging.java:1527)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)


This is the problem... whats is wrong?
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Did you tried with the old snippets and not this macros?
Hi,

doesn't work else... by the way, I used exactly the SAME project and code... no changes! It was running on B4A V7, and doesn't run anymore when compiled in B4A V8. Then, I modified adding Macros... same thing.
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Update: donwgraded to B4A V 7.3 - worked like a charm without any change ;) . #A LOT# of hard work to do the downgrade, including to recover the old AVD/SDK Managers with GUI, those don't exist anymore. But worked: my experience - if you app uses Firebase, the upgrade will generate problems - at least in the current B4A V8 environment.
 
Upvote 0

DonManfred

Expert
Licensed User
3. The line above and json was already referenced in V7 at the same way:
But it is now part of one of the macros.

Regarding the problem:
I did an SDK Update this morning.
I can confirm it here.

I am using V8. It was working a few days ago. I dont´think that B4A 8 is the problem.
Seems that something has changed in the newest Mavenartifacts.

I´m still investigation what the problem can be.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
But it is now part of one of the macros.

Regarding the problem:
I did an SDK Update this morning.
I can confirm it here.

I am using V8. It was working a few days ago. I dont´think that B4A 8 is the problem.
Seems that something has changed in the newest Mavenartifacts.

I´m still investigation what the problem can be.

I posted the same problem yesterday. I think I have found the cause an a temporary fix.

The problem is a firebase update on May 23rd. https://firebase.google.com/support/release-notes/android#20180502

there is a reference to this update

Changed: The methods subscribeToTopic() and unsubscribeFromTopic() on FirebaseMessaging now return a Task that can be used to see when the request has completed.

I think previously these methods returned void and now return Task.

My work around is as follows.

using the reflection library call the method.
B4X:
Private r As Reflector
   
    r.Target = fm
    r.RunMethod2("subscribeToTopic",TopicString,"java.lang.String")

Where TopicString is a string which is the topic to subscribe to.

The same applies to unsubscribe:

B4X:
    Private r As Reflector
 
   r.Target = fm
   r.RunMethod2("unsubscribeFromTopic",TopicString,"java.lang.String")

This is a temporary fix only!
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
I posted the same problem yesterday. I think I have found the cause an a temporary fix.

The problem is a firebase update on May 23rd. https://firebase.google.com/support/release-notes/android#20180502

there is a reference to this update

Changed: The methods subscribeToTopic() and unsubscribeFromTopic() on FirebaseMessaging now return a Task that can be used to see when the request has completed.

I think previously these methods returned void and now return Task.

My work around is as follows.

using the reflection library call the method.
B4X:
Private r As Reflector
  
    r.Target = fm
    r.RunMethod2("subscribeToTopic",TopicString,"java.lang.String")

Where TopicString is a string which is the topic to subscribe to.

The same applies to unsubscribe:

B4X:
    Private r As Reflector
 
   r.Target = fm
   r.RunMethod2("unsubscribeFromTopic",TopicString,"java.lang.String")

This is a temporary fix only!

Hello @Andrew (Digitwell) . GREAT solution, good job! Unfortunately, I'm not secure to use a "temporary" solution in a production app. The fail is in B4A V8 and so it needs to be fixed . My suggestion is that @Erel could analyse this case and publish a fix or a different integration method in V8... let's see what will happen. B4A V8 is a fantastic product - I can't wait for the time when I'll be able to migrate - now I need to use V 7 :(
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
But it is now part of one of the macros.

Regarding the problem:
I did an SDK Update this morning.
I can confirm it here.

I am using V8. It was working a few days ago. I dont´think that B4A 8 is the problem.
Seems that something has changed in the newest Mavenartifacts.

I´m still investigation what the problem can be.

I think that the right way to exactly reproduce the problem is:

- Create a FB app using V7 ...
- UPDATE the machine to V8...
- Try to compile/run....
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Fair enough. Yes, I'm sure the fix is coming but, in the meantime, I'm happy to put the fix into production and get the other benefits of using V8.

Cheers

Andrew
 
Upvote 0

itgirl

Active Member
Licensed User
Actually I've tried all the possibilities to reproduce the problem but with no luck at all, I've just updated the SDK today and tried again but everything work fine, im worried now lol cause everyone says theres a bug but i cant reproduce it :/
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Fair enough. Yes, I'm sure the fix is coming but, in the meantime, I'm happy to put the fix into production and get the other benefits of using V8.

Cheers

Andrew

Hi @Andrew (Digitwell) . Like I told, V8 is fantastic, like everything done by @Erel in B4X... but I spent 2 entire days trying to fix and doing the downgrade and need to launch products to my customers... then, until we have a definitive and fast fix, I don't have time to try again :( Unfortunately... because I'm a programmer and as programmer I like to use and test new and best tools... but the need to earn money is calling... the time that we spend with fixing/upgrading isn't paid by the customers (at least directly paid, besides we eventually can get feedback later in resources or productivity...)
 
Upvote 0

KMatle

Expert
Licensed User
Private r As Reflector

r.Target = fm
r.RunMethod2(
"subscribeToTopic",TopicString,"java.lang.String")

Doesn't work for me (B4A 8.0 + SDK 26 + everything updated). Any idea?

B4X:
Dim TopicString As String = "nothing"
    Private r As Reflector
    r.Target = fm
    r.RunMethod2("subscribeToTopic",TopicString,"java.lang.String")

B4X:
Error occurred on line: 20 (FirebaseMessaging)
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.firebase.iid.FirebaseInstanceId.zza(java.lang.String)' on a null object reference
    at com.google.firebase.messaging.FirebaseMessaging.subscribeToTopic(Unknown Source)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
    at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:817)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA$2.run(BA.java:360)
    at android.os.Handler.handleCallback(Handler.java:761)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:156)
    at android.app.ActivityThread.main(ActivityThread.java:6605)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:999)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:889)
 
Upvote 0

DonManfred

Expert
Licensed User
Upvote 0

KMatle

Expert
Licensed User
Upvote 0

Erel

Administrator
Staff member
Licensed User
This error has nothing to do with B4A v8 vs B4A v7. Google has changed an API and the library required an update to work properly: https://www.b4x.com/android/forum/threads/updates-to-internal-libraries.59340/#post-591400

B4A V8 is a fantastic product - I can't wait for the time when I'll be able to migrate - now I need to use V 7
The only reason that it worked when you test it with B4A v7 is that you used an old version of the Android SDK. You could have done the exact same thing with B4A v8.
There is nothing in B4A v7 that is not supported in v8.
 
Upvote 0
Top