Unity Firebase fails on load: "Failed to read Firebase options from the app's resources."

Viewed 3800

My Android build fails to initialise Firebase Messaging with the following error:

I/Unity   (30673): InitializationException: Failed to read Firebase options from the app's resources.  You'll need to either at least set App ID and API key or include google-services.json your app's resources.
I/Unity   (30673):   at Firebase.FirebaseApp.CreateAndTrack (Firebase.CreateDelegate createDelegate) [0x00000] in <filename unknown>:0
I/Unity   (30673):   at Firebase.FirebaseApp.Create () [0x00000] in <filename unknown>:0
I/Unity   (30673):   at Firebase.FirebaseApp.get_DefaultInstance () [0x00000] in <filename unknown>:0
I/Unity   (30673):   at Firebase.Messaging.FirebaseMessaging+Listener..ctor () [0x00000] in <filename unknown>:0
I/Unity   (30673):   at Firebase.Messaging.FirebaseMessaging+Listener.Create () [0x00000] in <filename unknown>:0
I/Unity   (30673):   at Firebase.Messaging.FirebaseMessaging..cctor () [0x00000] in <filename unknown>:0
I/Unity   (30673): Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Firebase.Messaging.FirebaseMessaging

I have downloaded and placed the google-services.json file in the project root and a google-services.xml file has been generated in Plugins/Android/Firebase/res/values that looks to have all the required values.

Also running the Google Play Games package if that would make any difference. Unity 5.3 and Firebase 4.1. Had it running in the past but had to re-install the packages and not working now.

1 Answers

Resolved - I was getting the same error on initialisation, in Unity. Key difference here was, I was using my own gradle for build, and the values inside Plugins/Android/Firebase/res/values.xml was not getting merged with final values.xml

Solution: Edited my gradle to include Firebase/res folder also to the res folders - Added following lines in mainTemplate.gradle under android block

    sourceSets {
        main {
                res.srcDirs += 'Firebase/res'
        }
}

Debugging Steps: 1. Verified google-services.xml inside Plugins folder 2. After building, verified the values inside Temp/ folder in Unity project 3. Found, the values inside Temp/Firebase is not in the main generated values.xml 4. Added line in mainTemplate.gradle to include Firebaes/res

Related