Android Question Facebook login

Stefano Di Chiano

Active Member
Licensed User
I'm implementing Facebook login via FirebaseAuth.
The main problem is that after I sign in (successfully) the app crash.
The secondary problem is that when I was using B4A Bridge the logs didn't show.
I tried with an emulator and I got the following error:
Logger connesso a: emulator-5554
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
onAuthStateChanged: com.google.firebase.auth.internal.zzl@4e82a120
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Facebook - SignIn
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Facebook - ResultArrived: Intent { (has extras) }
Facebook success: com.facebook.login.LoginResult@4e996dc0
signInWithCredential start
** Activity (main) Resume **
onAuthStateChanged: com.google.firebase.auth.internal.zzl@4e82a120
SignedIn: Stefano Di Chiano
AKXb0iY01ORBY88qFdYap3kvBlP2
Error occurred on line: 41 (Starter)
java.lang.NullPointerException
at anywheresoftware.b4a.BA.addLogPrefix(BA.java:587)
at anywheresoftware.b4a.keywords.Common.LogImpl(Common.java:191)
at b4a.logintest.starter._auth_signedin(starter.java:162)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
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.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5021)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
at dalvik.system.NativeStart.main(Native Method)
signInWithCredential complete: true
On line 41 of the starter service there is just: Log(User.Email).
I'm using B4A version 9.80.
If needed, this is my manifest:
'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="9" 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.Firebase)
CreateResourceFromFile(Macro, FirebaseAuth.FirebaseAuth)
'************ 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">509085083330445</string>
</resources>)
 

Stefano Di Chiano

Active Member
Licensed User
Ok, sorry. I used spoilers to not make it too long.
Anyway, this is the code:
Auth_SignedIn:
Sub Auth_SignedIn (User As FirebaseUser)
    Log("SignedIn: " & User.DisplayName)
    CallSub(Main, "SetState")
    Log(User.Uid)
    Log(User.Email)
End Sub
Line 41 is:
Line 41:
Log(User.Email)
The SetState used in Auth_SignedIn is:
SetState:
Sub SetState
    If Starter.auth.CurrentUser.IsInitialized Then
        Dim cu As FirebaseUser = Starter.auth.CurrentUser
        lblName.Text = "Hello: " & cu.DisplayName
    End If
    For Each btn As Button In Array (btnSignInFacebook, btnSignInGoogle)
        btn.Enabled = Not(Starter.auth.CurrentUser.IsInitialized)
    Next
    btnSignOut.Enabled = Starter.auth.CurrentUser.IsInitialized
End Sub
This is all from the facebook example on the tutorial.
 
Upvote 0

Stefano Di Chiano

Active Member
Licensed User
I switched to USB mode and it works well without errors.
It only crash when I sign in with Facebook using B4A Bridge.
It works perfectly both in USB mode and with android emulators.
 
Upvote 0

Stefano Di Chiano

Active Member
Licensed User
You are actually right. I don't know what happened but this morning I run it again and it worked perfectly even with B4A Bridge.
Could it have been a network problem?
 
Upvote 0
Top