【发布时间】:2020-11-03 15:33:50
【问题描述】:
自 8 月以来我没有接触过这段代码,它工作正常,但自从我昨天重新开始使用它后,我一直收到这个错误:
带标签:createUserWithEmail:failure
com.google.firebase.FirebaseException:发生内部错误。 [无法解析主机“www.googleapis.com”:没有与主机名关联的地址]
我的所有依赖项都已正确设置。我检查了无数次,并在 YouTube 上花费了数小时,重新下载了 json 文件,更新了 Android Studio 和我的模拟器。这是我最后的手段。我希望有人能帮帮忙。这是我的代码
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
Toast.makeText(Register.this, "Sign up success! Taking you to login...",
Toast.LENGTH_SHORT).show();
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(Register.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, e.getMessage());
Log.d(TAG, "FAIL");
}
});
【问题讨论】:
-
你的模拟器有网络吗?检查右上角的图标
-
您有正确的安全规则吗?
-
在没有 Internet 连接时出现此错误。是的,这样的错误有歧义,它可能是一个firebase错误,阻止了auth api清楚地发出“无连接错误”。
标签: java android firebase firebase-authentication