Android Question Firebase storage error: "Firebase Storage component is not present."

Tareq Khan

Member
Licensed User
Longtime User
Hi All,
I am using B4A v8.80, FirebaseStorage library v1.11. About a month ago, I wrote program to use Firebase Storage with these versions and it worked fine.

About a week ago, I updated SDKs using B4A SDK manager with Recommended items. I have followed the new steps mentioned in https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/ and updated the Manifest editor.

Now, whenever the program reaches the code below, it crashes.
B4X:
storage.Initialize("storage", bucket)
I am getting the error as shown below:
B4X:
Logger connected to:  motorola Moto G Play
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
Error occurred on line: 18 (Starter)
java.lang.NullPointerException: Firebase Storage component is not present.
    at com.google.android.gms.common.internal.Preconditions.checkNotNull(Unknown Source)
    at com.google.firebase.storage.FirebaseStorage.getInstanceImpl(com.google.firebase:firebase-storage@@17.0.0:74)
    at com.google.firebase.storage.FirebaseStorage.getInstance(com.google.firebase:firebase-storage@@17.0.0:125)
    at com.google.firebase.storage.FirebaseStorage.getInstance(com.google.firebase:firebase-storage@@17.0.0:89)
    at anywheresoftware.b4x.objects.FirebaseStorageWrapper.Initialize(FirebaseStorageWrapper.java:47)
    at b4a.test.starter._service_create(starter.java:153)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at b4a.test.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3212)
    at android.app.ActivityThread.-wrap5(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6165)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
** Service (starter) Start **

I changed back the Manifest Editor codes with the old snippets and still I am getting the same error.
All my Firebase storage related project are giving me the same error as shown above.


Below is my code in Activity Main:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Public Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
   
   
End Sub

Sub Activity_Resume
    If CheckForGooglePlayServices Then
        Label1.Text = "OK"
       
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
   
    Starter.storage.DownloadFile("/1.txt", File.DirInternal, "1.txt")
   
End Sub


Sub Storage_DownloadCompleted (ServerPath As String, Success As Boolean)
    ToastMessageShow($"DownloadCompleted. Success = ${Success}"$, True)

    If Not(Success) Then Log(LastException)
End Sub


Sub CheckForGooglePlayServices As Boolean
    Dim GoogleApiAvailablity As JavaObject
    GoogleApiAvailablity = GoogleApiAvailablity.InitializeStatic("com.google.android.gms.common.GoogleApiAvailability").RunMethod("getInstance", Null)
    Dim context As JavaObject
    context.InitializeContext
    If GoogleApiAvailablity.RunMethod("isGooglePlayServicesAvailable", Array(context)) <> 0 Then
        GoogleApiAvailablity.RunMethod("makeGooglePlayServicesAvailable", Array(context))
        Return False
    End If
    Return True
   
End Sub


Below is the code in Starter service:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public storage As FirebaseStorage
    Private bucket As String = "gs://xxxxxxxxx.appspot.com"
   
   
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    storage.Initialize("storage", bucket)
   
   
End Sub

Sub Service_Start (StartingIntent As Intent)

   

End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub

The Manifest editor:
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="26"/>
<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)

I checked CheckForGooglePlayServices() function, and it is returning True.

I have Firebase rules as follows:
B4X:
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write, delete: if true;
    }
  }
}


Can you please help?
 

DonManfred

Expert
Licensed User
Longtime User
and updated the Manifest editor
so you was using an old sdk installation?

I suggest to install a new SDK.

You can find the Setup-Instructions here. https://www.b4x.com/b4a.html
You also can watch this Video as it describes it clearly.

Start with a new Blank folder like you see in the Video.

Make sure to configure the ide to use the new SDK.

Alternatively you can use the ReadyToRun-SDK. Make sure to configure the ide to use the new SDK too.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
I get the same error. After update the SDK I get the error below when I compile my app.

I remove the old SDK and install a new SDK, but the problem remains.

I tried with the FirebaseStorage example from @Erel and same error.

Any tip are welcome to solved this problem.

B4X:
*** Service (starter) Create ***
starter_service_create (java line: 170)
java.lang.NullPointerException: Firebase Storage component is not present.
    at com.google.android.gms.common.internal.Preconditions.checkNotNull(Unknown Source:11)
    at com.google.firebase.storage.FirebaseStorage.getInstanceImpl(com.google.firebase:firebase-storage@@17.0.0:74)
    at com.google.firebase.storage.FirebaseStorage.getInstance(com.google.firebase:firebase-storage@@17.0.0:125)
    at com.google.firebase.storage.FirebaseStorage.getInstance(com.google.firebase:firebase-storage@@17.0.0:89)
    at anywheresoftware.b4x.objects.FirebaseStorageWrapper.Initialize(FirebaseStorageWrapper.java:47)
    at br.com.as2.testes.starter._service_create(starter.java:170)
    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 br.com.as2.testes.starter.onCreate(starter.java:56)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3339)
    at android.app.ActivityThread.-wrap4(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1677)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Can you post your manifest editor code?

Make sure to use CreateResourceFromFile: https://www.b4x.com/android/forum/threads/integrating-firebase-services.67692/

The errors occours in your FirebaseStorage example too.
"java.lang.NullPointerException: Firebase Storage component is not present."

This is the manifest code:
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="15" android:targetSdkVersion="26"/>
<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.

'************ Google Play Services Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
'************ Google Play Services Base (end) ************
'************ Firebase Base ************
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
'************ Firebase Base (end) ************
'************ Firebase Auth ************
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
'************ Firebase Auth (end) ************
 
Upvote 0
Top