Android Question java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process xxxx.

Humberto

Active Member
Licensed User
Longtime User
I did the follow

Change the manifest with
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)


I used a small software that I did some time ago to test some features than I tested with this test app and I had to recreate the project in Firebase and worked

Than I recreate the SOS software ( new one) in Firebase and I changed the application name ( test app ) to match the SOS app and tested and worked.

In the SOS App I still can not compile, I get this error bellow

B4X:
*** Service (firebasemessaging) Create ***
firebasemessaging_service_create (java line: 790)
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process hsp.sosapp. Make sure to call FirebaseApp.initializeApp(Context) first.
    at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.4:240)
    at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
    at com.google.firebase.messaging.FirebaseMessaging.getInstance(Unknown Source)
    at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.Initialize(FirebaseNotificationsService.java:97)
    at hsp.sosapp.firebasemessaging._service_create(firebasemessaging.java:790)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at hsp.sosapp.firebasemessaging.onCreate(firebasemessaging.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2408)
    at android.app.ActivityThread.access$1600(ActivityThread.java:138)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4950)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
    at dalvik.system.NativeStart.main(Native Method)

I tryed to use the same manifest from the test app but still could not compile


Bellow the manifest from the SOS app

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="14" android:targetSdkVersion="27"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.

AddPermission(android.permission.CAPTURE_AUDIO_OUTPUT)
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddPermission(android.permission.RECORD_AUDIO)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)

CreateResourceFromFile(Macro, Themes.LightTheme)

'#### NEW MANIFEST FIREBASE FOR B4A V8
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
'CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
'CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)

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

SetActivityAttribute(main, android:windowSoftInputMode, adjustPan|stateHidden)  
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission (android.permission.ACCESS_COARSE_LOCATION)

AddPermission(android.permission.WAKE_LOCK)

AddApplicationText(
   <provider
  android:authorities="${applicationId}.firebaseinitprovider"
  android:name="com.google.firebase.provider.FirebaseInitProvider"
  android:exported="false"
  android:initOrder="100" />
)
'************ Firebase Base (end) ************


The problem occurs when I try to initialize the Firebasemessaging ( fm.Initialize("fm")

B4X:
Sub Service_Create
    fm.Initialize("fm")
    Timer_beep.Initialize ( "Timer_Beep", 180000)
    Timer_beep.Enabled = False
    
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What about the two linked in the url?
>FirebaseAnalytics v1.02 and FirebaseAuth v1.05

And you are using the B4A SDK Manager? You have which version of the SDK Manager? Post a screenshot from the mainscreen of it.
You have updated all suggested items?
 
Upvote 0

Humberto

Active Member
Licensed User
Longtime User
What about the two linked in the url?
>FirebaseAnalytics v1.02 and FirebaseAuth v1.05
I didn´t understand


I used the IDE 8.50

I did all the changes and update, With the test app I can compile
 

Attachments

  • sdk_manager.png
    sdk_manager.png
    41.2 KB · Views: 541
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Humberto

Active Member
Licensed User
Longtime User
When I erase this lines fom the manifest I can´t receive the log and still the app crash.
 
Upvote 0

Humberto

Active Member
Licensed User
Longtime User
I made a modification in two projects "ttmapp" in attach ( works ) and "sosapp" can download with the link that doesnt works and I don´t know why

The SOSapp is in production and works with IDE 7.3. Now I´m trying to use with new IDE ( 8.5) and new firebase

I already create a new project in Google Firebase.

As a test I rename in "ttmapp" the project to "sosapp" and use the "google-services.json" from the "sosapp" project also works. Seems that the problem is not in firebase project.

B4X:
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(RuntimeException) java.lang.RuntimeException: Object should first be initialized (Panel).
Did you forget to call Activity.LoadLayout?
WakeLock already held.
*** Service (srv_location_firebase) Create ***
** Service (srv_location_firebase) Start **
*** Service (firebasemessaging) Create ***
Error occurred on line: 16 (FirebaseMessaging)
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process hsp.sosapp. Make sure to call FirebaseApp.initializeApp(Context) first.
    at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.4:240)
    at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
    at com.google.firebase.messaging.FirebaseMessaging.getInstance(Unknown Source)
    at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.Initialize(FirebaseNotificationsService.java:97)
    at hsp.sosapp.firebasemessaging._service_create(firebasemessaging.java:2877)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:352)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at hsp.sosapp.firebasemessaging.onCreate(firebasemessaging.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2408)
    at android.app.ActivityThread.access$1600(ActivityThread.java:138)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4950)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
    at dalvik.system.NativeStart.main(Native Method)
** Service (firebasemessaging) Start **

I get the last working version from "sosapp" and did again the steps to upgrade but still with problem





http://www.sostoken.com/d/sosapp_problem.zip
 

Attachments

  • ttmapp_201810.zip
    328.9 KB · Views: 243
Upvote 0

Humberto

Active Member
Licensed User
Longtime User
I did, as I told before, I could do the changes with "ttmapp" and works OK but the "sosapp" that is an application that was working and published at the google play is not working the modification and I did the same steps.

I still can´t find the problem
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Start with removing this lines
B4X:
   '#ExcludeClasses: .games, .drive, .fitness, .wearable, .measurement, .cast, .auth, .nearby
    #ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .vision, .gcm
    'remove the following line if you use AdMob
    #ExcludeClasses: .ads
    
    #AdditionalJar: android-support-v4.jar
They are ALL not needed anymore. #AdditionalJar: android-support-v4.jar was never needed.
 
Upvote 0

Humberto

Active Member
Licensed User
Longtime User
As I need to change "targetSdkVersion" to 27 all kind of error occurs in the software like the need for RuntimePermissions, problems with library "liblame".

Now everthing seems to be OK.

Thanks for the atention, As my software needs all the permission, I wrote to ask all of them at the first running, before do anything and now is ok

If someone is interesting can ask me
 
Upvote 0
Top