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.
I am getting the error as shown below:
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:
Below is the code in Starter service:
The Manifest editor:
I checked CheckForGooglePlayServices() function, and it is returning True.
I have Firebase rules as follows:
Can you please help?
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)
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?