0

I am getting strange exception from deep of Android:

java.lang.RuntimeException: Unable to resume activity {com.example.firebase/com.example.firebase.MainActivity}: java.lang.ClassCastException: com.google.android.gms.b.qf cannot be cast to com.google.firebase.auth.n
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2937)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2966)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2367)
    at android.app.ActivityThread.access$700(ActivityThread.java:168)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:177)
    at android.app.ActivityThread.main(ActivityThread.java:5493)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:525)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1225)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1041)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.google.android.gms.b.qf cannot be cast to com.google.firebase.auth.n
    at com.google.android.gms.b.aw.a(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.b(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.b.av.<init>(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.a(Unknown Source)
    at com.google.firebase.auth.FirebaseAuth.b(Unknown Source)
    at com.atlascoder.android.dollaruz.MainActivity.onResume(Unknown Source)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1209)
    at android.app.Activity.performResume(Activity.java:5450)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2922)
...

And it occurs within the onResume() callback for my AppCompatActivity:

...

FirebaseAuth mAuth;

@Override
protected void onResume(){
    super.onResume();

        if (mAuth == null) {
            mAuth = FirebaseAuth.getInstance();
            mAuth.signInAnonymously().addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    FirebaseUser user = mAuth.getCurrentUser();
                    if (user != null) {
                        setActiveFragment(mActiveFragmentTag);
                    } else {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_cant_auth_firebase), Toast.LENGTH_SHORT).show();
                    }
                }
            });
        } else {
            setActiveFragment(mActiveFragmentTag);
        }
}

...

It occurs no when first called but when I reopen the app after some time. And, what is more strange, I can't open the app even after restarting of the app (I mean restarting on device and not reinstalling).

My module's build.gradle content:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '24.0.0'
    defaultConfig {
        applicationId "com.example.firebase"
        minSdkVersion 14
        targetSdkVersion 23
        versionName '1.3'
        vectorDrawables.useSupportLibrary = true
        versionCode 4
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.google.android.gms:play-services-ads:9.2.1'
    compile 'me.grantland:autofittextview:0.2.+'
    compile 'com.google.firebase:firebase-auth:9.2.1'
    compile 'com.google.firebase:firebase-messaging:9.2.1'
    compile 'com.google.firebase:firebase-database:9.2.1'
    compile 'com.android.support:cardview-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
}

apply plugin: 'com.google.gms.google-services'

What could be wrong?

6
  • Do you need compile 'com.google.android.gms:play-services-ads:9.2.1'? Try removing it from your dependencies and try again. I am suspecting it might be causing the confusion. Commented Aug 10, 2016 at 21:11
  • Thanks Ishmael, but I need this dependency. But why do you think this should help? Is this just a suggestion? Commented Aug 10, 2016 at 21:21
  • It was just a suggestion to confirm it is causing conflict. Commented Aug 10, 2016 at 21:23
  • Hm, it is really strange( I have tried to build with earlier versions, 9.0.2 I remember, and with 23.4.0 of com.android.support but these didn't help. Thanks anyway, but it doesn't solve the problem. Commented Aug 10, 2016 at 21:27
  • Not sure if you resolved your error, but one possible cause could be if you changed your SHA1 key between your firebase project and and your google-services.json file. If you didn't touch it, then this is likely irrelevant, but figured I'd put this out there. Commented Oct 5, 2016 at 4:46

4 Answers 4

3

you can add following proguard rules in your proguard file to solve this problems.

-keepattributes Signature

The "Signature" attribute is required to be able to access generic types when compiling in JDK 5.0 and higher.

com.google.android.gms.b.qf is a generic types.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for this explanation of com.google.android.gms.b.qf! Actually the problem seems to be resolved via FirebaseAuth.getInstance().signOut() from comment from @changxw below. I just didn't checked it enough, but your detail is very helpful!
Whew, this solved yet another obscure runtime error, which doesn't appear in the debug apk, that you're going to get more upvotes for as more people attempt using the new Firebase database with Anonymous signin. If you're already using Google Play Services code, you can't use Google Sign-In, as they do in the Doc example, because it doesn't let you compile both '.addApi(Games.API)' and '.addApi(Auth.GOOGLE_SIGN_IN_API)'. Of the other authentication options, 'Anonymous' is by far the least complex and risky with Google Play Services code. This proguard tidbit should be in the Docs.
1

Using the code and versions of the dependencies you posted, I was able create crash stacks similar to yours, although the exception was:

java.lang.IncompatibleClassChangeError: com.google.android.gms.internal.zzaez

The problem went away when I changed the dependencies to use version 9.4.0 of the Firebase and Play Services libraries. See if that works for you.

There are many reports on SO of unusual Firebase problems caused by using older or inconsistent versions of libraries or tools. It seems wise to always use the latest versions, if possible.

In your case those would be:

compileSdkVersion 24
buildToolsVersion "24.0.1"

Support libs: 24.1.1

Firebase/PlayServices: 9.4.0

4 Comments

Thanks! I will try.
Unfortunately, this didn't help
@atlascoder: Does the device have a recent version of Google Play Services installed? The current version is 9.4.52.
Yes, the latest version
0

call FirebaseAuth.getInstance().signOut() in onDestroy of MainActivity after you sign in, you can try it.

Comments

0

As a workaround try minifyEnabled true -> minifyEnabled false It helped me. Sure, after this size of apk has grown, but app started to work.

1 Comment

Ok, I thought about it, but didn't try. It makes sense because I got strange classes and packages in the exception, it looks like there were performed some renaming. I'll try it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.