Reputation: 3063
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?
Upvotes: 0
Views: 2750
Reputation: 16
call FirebaseAuth.getInstance().signOut()
in onDestroy
of MainActivity
after you sign in, you can try it.
Upvotes: 0
Reputation: 185
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.
Upvotes: 3
Reputation: 61
As a workaround try
minifyEnabled true -> minifyEnabled false
It helped me. Sure, after this size of apk has grown, but app started to work.
Upvotes: 0
Reputation: 38289
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
Upvotes: 1