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?
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.