首页 > 解决方案 > FirebaseApiNotAvailable 异常

问题描述

当我在 genymotion 模拟器上按我的应用程序中的登录或注册按钮时,我收到错误 FirebaseApiNotAvailable 异常。但是当我在真实设备或 android studio 模拟器上运行我的应用程序时,它不会抛出任何错误。

我收到以下错误

java.lang.ClassCastException: com.google.firebase.FirebaseApiNotAvailableException cannot be cast to com.google.firebase.auth.FirebaseAuthException
    at com.example.dharmajyoti.LoginActivity$8.onComplete(LoginActivity.java:284)
    at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6680)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

我的毕业文件是

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
   compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
    applicationId "com.example.dharmajyoti"
    minSdkVersion 16
    targetSdkVersion 29
    versionCode 1
    versionName "1"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
lintOptions {
    checkReleaseBuilds false
    abortOnError false
     }
 }
dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'androidx.appcompat:appcompat:1.1.0'
      implementation 'com.google.android.material:material:1.1.0-alpha03'
      implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
      implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-database:19.3.1'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.3.0'
api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
  }

在下面的代码中我得到了错误

1.按下登录按钮时。

auth.signInWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if(task.isSuccessful())
            {....}
            else {
                       try {
                    FirebaseAuthException e = (FirebaseAuthException )task.getException();
                }
                catch(Exception ex)
                {
                    Toast.makeText(LoginActivity.this, "Login Failed: "+ex.getMessage(), Toast.LENGTH_SHORT).show();
                    pd.dismiss();
                }
             }

标签: androidfirebasegradlefirebase-authentication

解决方案


模拟器不支持 Firebase 身份验证。


推荐阅读