Android Question B4A 9.50 - java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process

Ahmet KOÇ

Member
Licensed User
Hi; I'm dealing with this problem and I can't solve it.

B4A 9.50
All library files and versions are complete. Even FirebaseAnalytics 1.12

<uses-sdk android: minSdkVersion = "14" android: targetSdkVersion = "28" />
<supports-screens android: largeScreens = "true"
android: normalscreens = "true"
android: smallscreens = "true"
android: anydensity = "true" />)

#if free
CreateResourceFromFile (Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile (Macro, FirebaseAuth.FirebaseAuth)
CreateResourceFromFile (Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile (Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile (Macro, FirebaseAnalytics.FirebaseAnalytics)
CreateResourceFromFile (Macro, FirebaseAdMob.FirebaseAds)
#end if

I get the error on the auth.Initialize ("auth") line.

java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process xxxxxxxxxxxx. Make sure to call FirebaseApp.initializeApp (Context) first.

I couldn't figure it out. This application worked through 23 versions. In fact, according to API28 compiled version is available in the market. My SDKs and Extra are fully installed. I don't understand what's changed.


My Manifest File ;

AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
'CreateResourceFromFile(Macro, Themes.DarkTheme)

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:largeHeap, "true" )

SetApplicationAttribute("android:theme","@android:style/Theme.Holo.Light.NoActionBar.Fullscreen")
SetActivityAttribute(popup,"android:theme","@android:style/Theme.Translucent.NoTitleBar")


#if free
CreateResourceFromFile (Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile (Macro, FirebaseAuth.FirebaseAuth)
CreateResourceFromFile (Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile (Macro, FirebaseNotifications.FirebaseNotifications)
CreateResourceFromFile (Macro, FirebaseAnalytics.FirebaseAnalytics)
CreateResourceFromFile (Macro, FirebaseAdMob.FirebaseAds)
#end if

CreateResourceFromFile ("google-services", "google-services.json")
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(android.permission.ACCESS_COARSE_LOCATION)
AddPermission(android.permission.ACCESS_FINE_LOCATION)
AddPermission(android.permission.ACCESS_MOCK_LOCATION)
AddPermission(android.permission.CALL_PHONE)
AddPermission(android.permission.CAMERA)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_CALENDAR)

SetApplicationAttribute(android:networkSecurityConfig, @xml/network_security_config)
CreateResource(xml, network_security_config.xml,
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
)

AddApplicationText(
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
)

AddApplicationText(
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="$PACKAGE$.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
)
CreateResource(xml, provider_paths,
<external-files-path name="name" path="shared" />
)
AddManifestText(<permission
android:name=".$PACKAGE$.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>)

AddApplicationText(
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/>
<meta-data android:name="com.google.android.gms.version" android:value="@Integer/google_play_services_version"/>
)

'************ Facebook Login ****************
AddApplicationText(<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>)

'************ Facebook Login (end) **********
CreateResource(values, facebook.xml, <resources>
<string name="facebook_app_id">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string>
</resources>)

'************ Google Play Services Base ************

AddApplicationText(
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
android:exported="false"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@Integer/google_play_services_version" />
)

'************ Google Play Services Base (end) ************
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

The Google Play Services Base snippet should be removed.
SetApplicationAttribute("android:theme","@android:style/Theme.Holo.Light.NoActionBar.Fullscreen")
Using a holo theme is a mistake.

Please upload the generated Objects\AndroidManifest.xml file.
 
Upvote 0

Ahmet KOÇ

Member
Licensed User
Please use [code]code here...[/code] tags when posting code.

The Google Play Services Base snippet should be removed.

Using a holo theme is a mistake.

Please upload the generated Objects\AndroidManifest.xml file.
 

Attachments

  • AndroidManifest.xml
    14.3 KB · Views: 135
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Make a test and set the manifest editor to:
B4X:
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$")
'End of default text.

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

Without anything else. Does it run?
 
Upvote 0

Ahmet KOÇ

Member
Licensed User
According to the proposal, my application worked as follows.

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

The only difference:
The application worked when I remove
CreateResourceFromFile (Macro, FirebaseAdMob.FirebaseAds).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm unable to reproduce it. It works fine here.

Libraries versions:
B4A_vu6rtY1w10.png


Try to reproduce it in a small project and upload it.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Possibly not related, but if you are using FirebaseAdMob, you need to have
B4X:
AddReplacement($ADMOB_APP_ID$, [your admob app id here])
in your manifest or the app will crash - even if you don't try to initialize an admob object.

- Colin.
 
Upvote 0

Ahmet KOÇ

Member
Licensed User
OK. I tried and the result is positive.

In addition, the following code should be added services_create under the starter service.

Dim MobileAds As MobileAds
mobileads.initialize
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
OK. I tried and the result is positive.

In addition, the following code should be added services_create under the starter service.

Dim MobileAds As MobileAds
mobileads.initialize
If you are using ads, yes - although I just released an update to an app & forgot to declare & initialize the MobileAds object however the ads work fine in the app. Perhaps @Erel can shed some light on what this does & why ads still work without it. (Having said that I'll add it in & release another update to that app)

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
It follows Google instructions.
Hmmm - there isn't much in the Firebase AdMob documentation about it either, except to say that it initializes the Google Mobile Ads SDK. The weird thing is that I discovered today I also forgot to include the initializer in another of my apps that I updated several weeks ago - this one generates 50k+ ad impressions per day - & it also works fine without it. I'll put it in next update, but it worries me when documentation states that x must be done & then everything works fine if it's not. (Just my inquiring mind wanting to know why it works when it seemingly shouldn't).

- Colin.
 
Upvote 0
Top