Android Question Firestore component is not present

gregorio_adrian_gimenez

Active Member
Licensed User
Hi, when executing the code fs.Initialize("Firestore",True), it generates the following unexpected error. I do not realize why it happens.
Version B4A 9.30.


main_setstate (B4A line: 225)
fs.Initialize("Firestore",True)
java.lang.NullPointerException: Firestore component is not present.
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:910)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@20.1.0:88)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@20.1.0:74)
at de.donmanfred.FirebaseFirestorewrapper.Initialize(FirebaseFirestorewrapper.java:43)
at com.apptravel.myapp.main._setstate(main.java:1614)
at com.apptravel.myapp.main$ResumableSub_Activity_Resume.resume(main.java:714)
at com.apptravel.myapp.main._activity_resume(main.java:689)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at com.apptravel.myapp.main.afterFirstLayout(main.java:110)
at com.apptravel.myapp.main.access$000(main.java:17)
at com.apptravel.myapp.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:819)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:210)
at android.app.ActivityThread.main(ActivityThread.java:5943)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:817)


Try other previous codes and it works well, in this case the difference is that add FireBase Storage, this can be a cause?
 

DonManfred

Expert
Licensed User
Post you manifest code.
I guess you need to add a registrar for storage

Add the following meta data to the ComponentDiscoveryService (manifest)
B4X:
          <meta-data
                android:name="com.google.firebase.components:com.google.firebase.storage.StorageRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
 
Last edited:

DonManfred

Expert
Licensed User
the difference is that add FireBase Storage
But the error happen when initializing Firestore; not Storage.
But i aggree that adding the storage could be the issue. Not a problem but a issue.
It just needs an additional entry to the manifest... See post above.
 
Last edited:

gregorio_adrian_gimenez

Active Member
Licensed User
HI !
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="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.FirebaseAnalytics)
'CreateResourceFromFile (Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile (Macro, FirebaseFirestore.Firebase)

CreateResourceFromFile (Macro, FirebaseAuth.FirebaseAuth)
CreateResourceFromFile (Macro, FirebaseNotifications.FirebaseNotifications)


'************ 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">1248062375370164</string>
   </resources>)

AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIzaSyCz72XcAIYdTeoBVd4jw18bA2MnaMdDvxA"/>
)

#additionaljar: com.android.support:support-v4

SetApplicationAttribute(android:theme, "@style/MyAppTheme")


CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">#0098FF</item>
        <item name="colorPrimaryDark">#007CF5</item>
        <item name="colorAccent">#AAAA00</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="android:windowTranslucentNavigation">false</item>
         <item name="android:windowTranslucentStatus">true</item>
    </style>
</resources>
)
AddApplicationText(
 <service android:name="com.google.firebase.components.ComponentDiscoveryService" >
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
             <meta-data
                android:name="com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.storage.StorageRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
        </service>
)
 

DonManfred

Expert
Licensed User
AddApplicationText(
<
service android:name="com.google.firebase.components.ComponentDiscoveryService" >
<meta-data
android:name=
"com.google.firebase.components:com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
<meta-data
android:name=
"com.google.firebase.components:com.google.firebase.iid.Registrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
<meta-data
android:name=
"com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
<meta-data
android:name=
"com.google.firebase.components:com.google.firebase.storage.StorageRegistrar"
android:value="com.google.firebase.components.ComponentRegistrar" />
</
service>
)
if you add a new ComponentDiscoveryService then you need to add it with all needed components.
Add the registrar for firestore
 

DonManfred

Expert
Licensed User
replace
B4X:
AddApplicationText(
 <service android:name="com.google.firebase.components.ComponentDiscoveryService" >
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
             <meta-data
                android:name="com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.storage.StorageRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
        </service>
)
with

B4X:
AddApplicationText(
 <service android:name="com.google.firebase.components.ComponentDiscoveryService" >
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
             <meta-data
                android:name="com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <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"/>

        </service>
)
And make sure it is placed at the end of the manifest. No other ComponentDiscoveryService follows...
 
Last edited:
Top