yalcin-ata / godot-android-plugin-firebase

Godot 3.2.2 Android plugin for Firebase
44 stars 12 forks source link

Default FirebaseApp failed to initialize because no default options were found #5

Closed myood closed 3 years ago

myood commented 3 years ago

Hey,

I've forked your project, removed everything except analytics and authentication, rebuild it and exported my godot project. The export itself succeeds, but the app crashes on startup:

2020-07-19 14:58:06.448 12724-12724/com.godot.game W/FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
2020-07-19 14:58:06.448 12724-12724/com.godot.game I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
2020-07-19 14:58:06.600 12724-12724/com.godot.game I/GodotPluginRegistry: Initializing Godot plugin Firebase
2020-07-19 14:58:06.609 12724-12724/com.godot.game I/GodotPluginRegistry: Completed initialization for Godot plugin Firebase
2020-07-19 14:58:08.841 12724-12724/com.godot.game W/FirebaseApp: Default FirebaseApp failed to initialize because no default options were found. This usually means that com.google.gms:google-services was not applied to your gradle project.
2020-07-19 14:58:08.842 12724-12724/com.godot.game D/Firebase: Analytics initializing
2020-07-19 14:58:08.883 12724-12724/com.godot.game D/Firebase: Analytics initialized
2020-07-19 14:58:08.883 12724-12724/com.godot.game D/Firebase: Authentication initializing
2020-07-19 14:58:08.893 12724-12724/com.godot.game D/AndroidRuntime: Shutting down VM
2020-07-19 14:58:08.895 12724-12724/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.godot.game, PID: 12724
    java.lang.IllegalArgumentException: Given String is empty or null
        at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(com.google.android.gms:play-services-basement@@17.1.1:5)
        at com.google.android.gms.auth.api.signin.GoogleSignInOptions$Builder.zac(com.google.android.gms:play-services-base@@17.1.0:55)
        at com.google.android.gms.auth.api.signin.GoogleSignInOptions$Builder.requestIdToken(com.google.android.gms:play-services-base@@17.1.0:29)
        at org.godotengine.androidplugin.firebase.AuthenticationGoogle.init(AuthenticationGoogle.java:68)
        at org.godotengine.androidplugin.firebase.Authentication.init(Authentication.java:52)
        at org.godotengine.androidplugin.firebase.Firebase.initFirebase(Firebase.java:169)
        at org.godotengine.androidplugin.firebase.Firebase.access$100(Firebase.java:37)
        at org.godotengine.androidplugin.firebase.Firebase$1.run(Firebase.java:129)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Note: google-services and firebase plugin json files are included in the export per instructions

I followed all the steps in your instruciton, especially adding dep to google-services and applying google-services plugin in android/build/build.gradle:

sed "/^\/\/CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN.*/a classpath 'com.google.gms:google-services:4.3.3'" -i android/build/build.gradle
sed "/^\/\/CHUNK_GLOBAL_BEGIN.*/a apply plugin: 'com.google.gms.google-services'" -i android/build/build.gradle

This results in:

diff --git a/android/build/build.gradle b/android/build/build.gradle
index f1fd716c..a161abe9 100644
--- a/android/build/build.gradle
+++ b/android/build/build.gradle
@@ -17,6 +17,7 @@ buildscript {
         classpath libraries.androidGradlePlugin
         classpath libraries.kotlinGradlePlugin
 //CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN
+classpath 'com.google.gms:google-services:4.3.3'
 //CHUNK_BUILDSCRIPT_DEPENDENCIES_END
     }
 }
@@ -115,6 +116,7 @@ android {

     // Both signing and zip-aligning will be done at export time
     buildTypes.all { buildType ->
+resValue "string", "server_client_id", "######"
         buildType.zipAlignEnabled false
         buildType.signingConfig null
     }
@@ -163,4 +165,5 @@ android {
 }

 //CHUNK_GLOBAL_BEGIN
+apply plugin: 'com.google.gms.google-services'
 //CHUNK_GLOBAL_END

Not sure if it's relevant, but after successful export, the apply plugin google-services is missing from build.gradle (along with some other stuff too):

root@557ece530399:/dungeon-puzzle# godot --quiet --export-debug "Android" export/debug.apk
root@557ece530399:/dungeon-puzzle# echo $?
0

root@557ece530399:/dungeon-puzzle# git diff

diff --git a/android/build/build.gradle b/android/build/build.gradle
index f1fd716c..ec454fd4 100644
--- a/android/build/build.gradle
+++ b/android/build/build.gradle
@@ -115,6 +115,7 @@ android {

     // Both signing and zip-aligning will be done at export time
     buildTypes.all { buildType ->
+resValue "string", "server_client_id", "######"
         buildType.zipAlignEnabled false
         buildType.signingConfig null
     }

I've run out of ideas. Does this ring a bell? What should I double-check next?

yalcin-ata commented 3 years ago

Hi,

all your manual additions should be before or after the.. _BEGIN /_END stuff (CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN, etc). These lines are "left overs" from the previous (deprecated) build system. (At least they are not documented for the new v1 plugin build system.)

I hope this was helpful.

myood commented 3 years ago

Yes, did the trick! Thanks!

Your instructions are correct, only these legacy parts a little misleading. A little improvement for consideration - maybe you could emphasize putting them above a little more with explanation to ignore _BEGIN/_END stuff?

Correct sed invocation, for the record:

sed "/^\/\/CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN.*/i classpath 'com.google.gms:google-services:4.3.3'" -i android/build/build.gradle
sed "/^\/\/CHUNK_GLOBAL_BEGIN.*/i apply plugin: 'com.google.gms.google-services'" -i android/build/build.gradle
yalcin-ata commented 3 years ago

Cool :-)