Android 无法通过Firebase进行身份验证
我正在尝试使用通过控制台添加的凭据在模拟器上登录Firebase 代码如下:Android 无法通过Firebase进行身份验证,android,firebase,kotlin,firebase-authentication,Android,Firebase,Kotlin,Firebase Authentication,我正在尝试使用通过控制台添加的凭据在模拟器上登录Firebase 代码如下: val auth = FirebaseAuth.getInstance() auth.signInWithEmailAndPassword(email, password) .addOnCompleteListener(this) { task -> if (task.isSuccessful) { // ... }
val auth = FirebaseAuth.getInstance()
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// ...
} else {
// ...
}
}
永远不会触发OnCompleteListener回调
我遵循了Firebase文档中的指导原则
谷歌服务json文件
项目依赖关系
应用程序依赖项
已启用电子邮件/密码登录方法
知道我做错了什么吗
渐变文件-项目:
buildscript {
ext.kotlin_version = '1.2.60'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle文件-应用程序
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "..."
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
您的电子邮件或密码有效吗 您可以添加“addOnFailureListener”以查看实际发生的情况
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// ...
} else {
// ...
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(context, e.getMessage(),Toast.LENGTH_SHORT).show();
}
});
尝试在build.gradle文件中添加以下依赖项:-
implementation 'com.google.firebase:firebase-core:16.0.1'
我还建议您使用最新的firebase依赖项。我通过
添加新的仿真器
在开发者控制台中启用Identity Toolkit API错误仅在新模拟器上的logcat中可见
此解决方案可能对使用仿真器并尝试过所有建议答案的用户有所帮助…Plz share gradle files@345是否将SHA key放入firebase?@Raj我已共享了gradle文件。是的,SHA-1 key已设置。@345是否尝试将task.getException记录在if task.issessful语句的其他部分,要真正了解问题所在,凭据是有效的。onFailure也没有启动。或者您必须将firebase身份验证依赖项更新到新版本。现在是16.0.2我已更新到最新的依赖项,但问题仍然存在。您是否已添加internet权限?您是否可以尝试在您的项目build.gradle中的AllProject->repositories中添加maven{url},然后清理/重建againI添加了核心依赖项并更新了其他依赖项,但问题仍然存在。同时将google services更新为classpath'com.google.gms:google services:4.0.2'我这样做了,但仍然没有成功: