Android Question [SOLVED] Error in FirebaseMessaging service

wizard699

Active Member
Licensed User
Longtime User
I've a new error an all app that include Firebase, after updating Internal Library Firebase Analitycs.

Error is at at the stsrt of app

firebasemessaging_subscribetotopics (java line: 264)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging)


All my app crash in the same point!!!
What's changed?
 
Last edited:

wizard699

Active Member
Licensed User
Longtime User
This is all error log

--------- beginning of crash
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
firebasemessaging_subscribetotopics (java line: 246)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at it.xxxx.appmobile.firebasemessaging._subscribetotopics(firebasemessaging.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 
Upvote 0

wizard699

Active Member
Licensed User
Longtime User
Sure!

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

'******************** orientamento **********************
SetActivityAttribute(Home, android:screenOrientation, "portrait")


' ***************  imposto il thema da utilizzare ****************
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

' ***************  definisco le costanti assegnate ai colori
CreateResource(values, colors.xml,
<resources>
   <color name="actionbar">#018ABE</color>
   <color name="statusbar">#007CF5</color>
   <color name="textColorPrimary">#0000FF</color>
   <color name="navigationBar">#ff006db3</color>
</resources>
)

' **************** definisco gli attributi specifici del tema
CreateResource(values, theme.xml,
<resources>
  <style name="MyAppTheme" parent="@android:style/Theme.AppCompat.Light.NoActionBar">
      <item name="android:colorPrimary">@color/actionbar</item> <!-- action bar -->
      <item name="android:colorPrimaryDark">@color/statusbar</item> <!-- status bar -->
      <item name="android:colorAccent">#AAAA00</item> <!-- Seekbar,, checkboxes,, switches,, etc. -->
      <item name="android:textColorPrimary">@color/textColorPrimary</item> <!-- ? -->
      <item name="android:textColorSecondary">#6699CC</item> <!-- inactive editText line,, scrollbar -->
      <item name="android:textColor">#000000</item> <!-- menu text,, msgbox title -->
      <item name="android:textColorLink">#b71c1c</item>
      <item name="android:textColorHighlight">#FF2424</item>
      <item name="android:windowNoTitle">true</item>
      <item name="android:windowFullscreen">true</item>
      <item name="android:backgroundDimEnabled">true</item>
      <item name="android:windowContentOverlay">@null</item>
      <item name="android:windowBackground">@android:color/transparent</item>
      <item name="android:windowIsTranslucent">true</item>
  </style>

  <style name="MyThemeTransparent" parent="android:style/Theme.Translucent.NoTitleBar">
    
  </style>

</resources>
)

' ************* è possibile definire configurazioni specifiche dei temi associate alle versioni ANDROID
'CreateResource(values-v20, theme.xml,
'<resources>
'    <style name="LightTheme" parent="@android:style/Theme.Material.Light">
'        <item name="android:colorPrimary">@color/actionbar</item>
'        <item name="android:colorPrimaryDark">@color/statusbar</item>
'        <item name="android:textColorPrimary">@color/textColorPrimary</item>
'        <item name="android:navigationBarColor">@color/navigationBar</item>
'    </style>
'</resources>
')


'SetActivityAttribute(main, android:theme, @android:style/Theme.AppCompat.Translucent.NoTitleBar)
SetActivityAttribute(main, android:theme, "@style/MyAppTheme")


'******** enable no-ssl communications
CreateResourceFromFile(Macro, Core.NetworkClearText)


'**************** Notify permission *************
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseRemoteConfig.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)



'************ Firebase Crashlytics *********************
AddApplicationText(
 <provider
            android:name="com.crashlytics.android.CrashlyticsInitProvider"
            android:authorities="$PACKAGE$.crashlyticsinitprovider"
            android:exported="false"
            android:initOrder="100" />
           )
          
CreateResource(values, com_crashlytics_build_id.xml,
<resources xmlns:tools="http://schemas.android.com/tools">
<string tools:ignore="UnusedResources,,TypographyDashes" name="com.crashlytics.android.build_id"
   translatable="false">xxxxxx6c696e67</string>
</resources>)

' il guid va modificato per ogni RELEASE ^^^^^^^^^^^^^^^^^^^^
'************ Firebase crashlytics (end) ***************



AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_NETWORK_STATE)

' permission install
AddPermission(android.permission.REQUEST_INSTALL_PACKAGES)

AddManifestText(
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />)
 
Upvote 0

wizard699

Active Member
Licensed User
Longtime User
Erel, I've inserted also CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase) into Manifest.

but nothing change.

Before update Analitycs 1.12 and updating SDK Manager, all the apps (7) goes without any problem.

Now all apps crash after Starter, invoking CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")

Something was certain changed.
 
Upvote 0

wizard699

Active Member
Licensed User
Longtime User
Yes all reccomanded are updated, togheter the Analitycs 1.12.
This is the problem. Before all ok ... after these update ... all crash.

I've update also PAth with C:\Program Files\Java\jdk1.8.0_231\bin\javac.exe

These are all the update that I've done.
 
Upvote 0

wizard699

Active Member
Licensed User
Longtime User
Erel, I've replicated a small project with also Main + 1 Home activity.
The code in Manifest is simple

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
'CreateResourceFromFile(Macro, FirebaseAdMob.FirebaseAds)
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)

.... and the problema was the same.

I've executed also SDK MANAGER ... and all the library reccomended are ok.

The error is the same

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
no utente
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
Inizio Service Start
firebasemessaging_subscribetotopics (java line: 268)
java.lang.RuntimeException: Object should first be initialized (FirebaseMessaging).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
    at it.xxx.appmobile.firebasemessaging._subscribetotopics(firebasemessaging.java:268)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1179)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Library:
Core (9.20)
Firebase Analitycs (1.12)
Firebase Auth (1.06)
Firebase Notifications (1.21)
Firebase RemoteConfig (2.50)
 
Upvote 0

wizard699

Active Member
Licensed User
Longtime User
Yes Erel!! Is RemoteConfig!!! And go without it.
Thanks a lot.

But RemoteConfig will it continue to work without the Macro?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
@DonManfred please update the macro in FirebaseRemoteConfig and add this code to ComponentDiscoveryService:
B4X:
  <meta-data
                android:name="com.google.firebase.components:com.google.firebase.storage.StorageRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <meta-data
               android:name="com.google.firebase.components:com.google.firebase.firestore.FirestoreRegistrar"
               android:value="com.google.firebase.components.ComponentRegistrar"/>

           <meta-data
                    android:name="com.google.firebase.components:com.google.firebase.database.DatabaseRegistrar"
                    android:value="com.google.firebase.components.ComponentRegistrar"/>
                <meta-data
                android:name="com.google.firebase.components:com.google.firebase.messaging.FirebaseMessagingRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />

You will then need to remove CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase) from the manifest. This is explained in the FirebaseRemoteConfig instructions.
 
Upvote 1

wizard699

Active Member
Licensed User
Longtime User
Yes EREL, sure!
In fact, before update Analitycs 1.12, the Macro CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase) was commentend!
Now I will have to keep it until release new macro in FirebaseRemoteConfig

Thanks a lot!
 
Upvote 0
Top