firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
833 stars 429 forks source link

FirebaseApp failed to initialize because no default options were found. #660

Closed fsener closed 4 years ago

fsener commented 4 years ago

Please fill in the following fields:

Unity editor version: 2018.4.3f Firebase Unity SDK version: 6.14 Source you installed the SDK (.unitypackage or Unity Package Manager): Unity Package Manager Firebase plugins in use (Auth, Database, etc.): Analytics 17.3, Common 19.3 Messaging 12.0.1 Additional SDKs you are using (Facebook, AdMob, etc.): Facebook, Mopub, Safedk, OneSignal, Fabric Platform you are using the Unity editor on (Mac, Windows, or Linux): Mac Platform you are targeting (iOS, Android, and/or desktop): iOS & Android Scripting Runtime (Mono, and/or IL2CPP): IL2CPP

Please describe the issue here:

Hi,

Just installed Firebase analytics unity plugins through UPM and having problem about building Android project properly.

Even though I have added both google-services.json, GoogleService-Info.plist to my Assets folder and python script actually generates proper XML out of it while building for Android, I was getting;

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.

I have "fixed" this problem via adding res.srcDirs += 'Firebase/res' inside my Gradle sourcesets.

However now whenever I try launch the game for the first time it crashes saying

Caused by java.lang.VerifyError Superclass com.google.firebase.iid.zzb of com.google.firebase.messaging.FirebaseMessagingService is declared final (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/my.awesome.game-5q3lbui_dMtQpR5oh26Sqw==/base.apk!classes2.dex) java.lang.VMClassLoader.findLoadedClass (VMClassLoader.java) java.lang.ClassLoader.findLoadedClass (ClassLoader.java:738) java.lang.ClassLoader.loadClass (ClassLoader.java:363) java.lang.ClassLoader.loadClass (ClassLoader.java:312) android.app.AppComponentFactory.instantiateService (AppComponentFactory.java:129) androidx.core.app.CoreComponentFactory.instantiateService (CoreComponentFactory.java:66) android.app.ActivityThread.handleCreateService (ActivityThread.java:4264) android.app.ActivityThread.access$1800 (ActivityThread.java:272) android.app.ActivityThread$H.handleMessage (ActivityThread.java:2071) android.os.Handler.dispatchMessage (Handler.java:107) android.os.Looper.loop (Looper.java:237) android.app.ActivityThread.main (ActivityThread.java:8016) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1076)

After this crash it launches OK, but whenever I try to sign-in using Play Games Services, it crashes again;

Caused by java.lang.VerifyError Verifier rejected class com.google.android.gms.auth.api.signin.GoogleSignInClient: int com.google.android.gms.auth.api.signin.GoogleSignInClient.zzach() failed to verify: int com.google.android.gms.auth.api.signin.GoogleSignInClient.zzach(): [0xF] 'this' argument 'Reference: com.google.android.gms.common.GoogleApiAvailability' not instance of 'Precise Reference: com.google.android.gms.common.zzf' (declaration of 'com.google.android.gms.auth.api.signin.GoogleSignInClient' appears in /data/app/my.awesome.game-5q3lbui_dMtQpR5oh26Sqw==/base.apk!classes2.dex) com.google.android.gms.auth.api.signin.GoogleSignIn.getClient my.awesome.game.gpgs.login.GpgsLogin.safedk_GoogleSignIn_getClient_4d339ed2050e61cc32edc7f20a64e187 (Unknown Source:32) my.awesome.game.gpgs.login.GpgsLogin.initialize (GpgsLogin.java:35) my.awesome.game.GuestAuthenticationProxyActivity.onCreate (GuestAuthenticationProxyActivity.java:43) android.app.Activity.performCreate (Activity.java:7957) android.app.Activity.performCreate (Activity.java:7946) android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1307) android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3530)

Here's that part of GpgsLogin.java;

public void initialize(Activity activity, View viewForGamePopups) { this.activity = activity; this.viewForGamePopups = viewForGamePopups; GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build(); googleSignInClient = GoogleSignIn.getClient(activity, googleSignInOptions); }

Any ideas?

What's the issue repro rate? (eg 100%, 1/5 etc) 100%

google-oss-bot commented 4 years ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

gromilQaaaa commented 4 years ago

Getting totally the same problem. Android app crashes, but not always. The error in log is: Rejecting re-init on previously-failed class java.lang.Class<com.google.firebase.messaging.FirebaseMessagingService>: java.lang.IllegalAccessError: Class com.google.firebase.iid.zzc extended by class com.google.firebase.messaging.FirebaseMessagingService is inaccessible (declaration of 'com.google.firebase.messaging.FirebaseMessagingService' appears in /data/app/com.gamepoint.bingo-1/base.apk:classes2.dex) 05-06 12:41:45.359 25379 25379 I art : at java.lang.Class java.lang.VMClassLoader.findLoadedClass!(java.lang.ClassLoader, java.lang.String) (VMClassLoader.java:-2) 05-06 12:41:45.359 25379 25379 I art : at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:742) 05-06 12:41:45.359 25379 25379 I art : at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:362) 05-06 12:41:45.359 25379 25379 I art : at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312) 05-06 12:41:45.359 25379 25379 I art : at void android.app.ActivityThread.handleCreateService(android.app.ActivityThread$CreateServiceData) (ActivityThread.java:3323) 05-06 12:41:45.359 25379 25379 I art : at void android.app.ActivityThread.-wrap5(android.app.ActivityThread, android.app.ActivityThread$CreateServiceData) (ActivityThread.java:-1) 05-06 12:41:45.359 25379 25379 I art : at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1665) 05-06 12:41:45.359 25379 25379 I art : at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:105) 05-06 12:41:45.359 25379 25379 I art : at void android.os.Looper.loop() (Looper.java:156) 05-06 12:41:45.359 25379 25379 I art : at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6605) 05-06 12:41:45.359 25379 25379 I art : at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2) 05-06 12:41:45.359 25379 25379 I art : at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:999) 05-06 12:41:45.359 25379 25379 I art : at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:889)

I'm using latest Appsflyer, Onesignal, Firebase Deeplinks, Analytics, Crashlytics 6.14 from UPM. I already added link.xml, but it doesn' help:

<assembly fullname="Firebase.Crashlytics" ignoreIfMissing="1">
    <namespace fullname="Firebase.Crashlytics" preserve="all"/>
</assembly>

<assembly fullname="Firebase.App" ignoreIfMissing="1">
    <namespace fullname="Firebase.App" preserve="all"/>
</assembly>

Please help!

chkuang-g commented 4 years ago

@fsener @gromilQaaaa Thank you for the information.

Based on the callstack, I suspect there are some issues when resolving Android libraries.

I noticed that several Unity plugins ships with PlayServicesResolver or ExternalDependencyManager (new name for PlayServicesResolver, EDM4U in brief) with their .unitypackage, ex. OneSignal and Mopub. When you install Firebase through UPM, you will need to make sure all those libraries are removed before installing Firebase through UPM, since it will install External Dependency Manager through UPM as well. If not removed, there will be installation conflict. When this happens, Unity will have trouble to load Firebase editor tool or EDM4U. This installation conflict issue is quite complicated so we do not have a good solution for every scenario yet.

So the first thing you can try is:

If the issue is installation conflict, your issue should be resolve at this point.

Could you try this first and see if this works for you? Shawn

fsener commented 4 years ago

Hello,

My first problem is that I was missing implementation project(':Firebase') in my custom mainTemplate.gradle because our project is not using DEPS and I didn't realize it was missing, after that Firebase initialized correctly without needing to add res.srcDirs += 'Firebase/res'

Second problem (google play login) seems to be fixed after changing all Firebase libraries to the same GMS version which is 12.0.1 for us.

Thank you

patm1987 commented 4 years ago

Thanks for resolving this, I'll add a note about this to our internal troubleshooting document. Is it safe to close this issue?

fsener commented 4 years ago

Thanks for resolving this, I'll add a note about this to our internal troubleshooting document. Is it safe to close this issue?

Yes, thank you.