15

I am getting this crash in about 70% of devices in the market. However it never came up during testing.

public class MyApp extends Application{
public void onCreate() {
        super.onCreate();
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);
        FirebaseAuth.getInstance().signInAnonymously();
    }
}

This is the error.

    Fatal Exception: java.lang.RuntimeException: Unable to create application com.mycompany.myapp.activities.MyApp: java.lang.ClassCastException: com.google.android.gms.internal.hc cannot be cast to com.google.firebase.auth.c
com.google.android.gms.internal.hc cannot be cast to com.google.firebase.auth.c
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4927)
    at android.app.ActivityThread.access$1500(ActivityThread.java:153)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5633)
    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:896)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassCastException: com.google.android.gms.internal.hc cannot be cast to com.google.firebase.auth.c
    at com.google.android.gms.internal.aa.a(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.a(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.d(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.<init>(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.<init>(Unknown Source)
    at com.google.android.gms.internal.z.<init>(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.c(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.b(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.b(Unknown Source)
    at com.tesseractmobile.solitairesdk.activities.SolitaireApp.onCreate(SolitaireApp.java:123)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1020)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4924)

I am using firebase 9.2.1

compile "com.google.firebase:firebase-core:${firebaseVersion}"
compile "com.google.firebase:firebase-database:${firebaseVersion}"
//For dynamic links
compile "com.google.firebase:firebase-invites:${firebaseVersion}"
//Authentication - for logging winning games
compile "com.google.firebase:firebase-auth:${firebaseVersion}"

Right now I am just disabling firebase in our app. We were just testing it to see how stable it is. I have no clue why it worked on all of our test devices then crashed this bad in the wild.

Update: I was able to get a video of the issue using Firebase Test Lab. It happened when the robotest clicked on an Ad (Ad supported app) then came back to the app. So maybe it has something to do with FirebaseAuth.getInstance().signInAnonymously(); getting called twice? However Application.onCreate() should only be called once. I know there is a known bug with Firebase crash reporting that will cause two Application instances to be created but we are not using that sdk util they fix the issue.

theJosh
  • 2,894
  • 1
  • 28
  • 50
  • *about 70% of devices* that is a huge number for a crash. Maybe you could use online test farm to test against firebase crash. – ישו אוהב אותך Jul 23 '16 at 00:46
  • @itnotmenow I am looking for a new testing method that would find this. We do unit testing and connected tests on a small device farm. We only have a dozen devices to test with. As a small company it's a financial hardship to do more than we already do. So some problems just need to be found by customers. – theJosh Jul 23 '16 at 21:16
  • @theJosh Have you downloaded `google-services.json` to your app directory and authorized both package names and SHA1 signature at Firebase Console? – JP Ventura Aug 09 '16 at 01:10

3 Answers3

3

I used Firebase Test Lab to find the issue. It crashed on one of their devices and I watched the video of what happened. Our app is ad supported. We don't click our own ads during testing so this never came up. The crash happens after a user clicks an ad and then reenters the app. The solution I found was the same as this issue. FirebaseApp with name [DEFAULT] doesn't exist

        if (!FirebaseApp.getApps(this).isEmpty()){ 
            FirebaseDatabase.getInstance().setPersistenceEnabled(true);
            FirebaseAuth.getInstance().signInAnonymously();
        }

I think Application.onCreate() is called more than once. Though that should never happen.

EDIT: THIS ANSWER DOES NOT WORK

After a full week of testing by a 4 person QA team. Running 58 unit and connected tests with espresso on 7 test devices. Then running multiple tests on dozens of cloud devices using Google Test Lab. The problem never happened. Then on release day, 500 crashes in the first half hour!? 70% crash rate. So back to square one.

FINAL ANSWER: Proguard issue

I added these two line to my proguard-rules.pro

#Firebase Authentication
-keepattributes Signature
-keepattributes *Annotation*

Problem solved.

Community
  • 1
  • 1
theJosh
  • 2,894
  • 1
  • 28
  • 50
-2

Hi I have a similar problem, after days without solution, I found what it's a version problem with the appcompat, so i Changed this:

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'

to this:

compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:support-v4:23.3.0'

in the app graddle and my problem solved, sorry for my English

-2

Update your build.gradle:

// Firebase Gradle
compile "com.google.firebase:firebase-auth:9.4.0"
compile 'com.google.firebase:firebase-storage:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
Mitesh Machhoya
  • 404
  • 2
  • 8