android - 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();
}
}
解决方案
模拟器不支持 Firebase 身份验证。
推荐阅读
- javascript - 如何通过旧的 javascript 在 ubuntu 中调用 sleep 二进制文件?
- ruby-on-rails - 使用 sidekiq-cron 自动删除帖子
- python - Dash 获取会话对象变量会引发可怕的运行时错误
- ios - 无法注册捆绑标识符并且找不到配置文件?
- python-3.x - 从 dict 调用值以在数据框中创建布尔列
- javascript - 为什么我的 post 请求没有得到 readyState=4 和 status=200?
- apache-flink - 在 Flink 中避免使用 trait 下的 case 类的通用序列化器
- bash - 查询服务器和数据库的脚本,然后显示操作菜单(停止应用程序,启动应用程序),然后停止并导出数据库
- angular - 代码在 chrome 调试器中没有按预期工作
- html - 使用 VBA 提取 html 中的 JSON DATA 表;将 Apps 脚本转换为 VBA