首页 > 解决方案 > 当我为我的班级初始化 Fire 基础身份验证时,应用程序停止

问题描述

当我为我的班级初始化 Fire 基础身份验证时,应用程序停止
可能会在 gradle 中出现问题,但每件事都有一个托盘

这是我的代码

class Test : AppCompatActivity() {

lateinit var mAuth: FirebaseAuth

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_test)

    mAuth = FirebaseAuth.getInstance()

}
}    

这是我的毕业典礼

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.google.firebase:firebase-config:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.0'

}

标签: androidfirebase-realtime-databasekotlinfirebase-authentication

解决方案


您正在使用旧版本的 Firebase 依赖项,并且缺少 Google 服务插件。要解决此问题,请使用以下依赖项:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    implementation 'com.google.firebase:firebase-database:16.0.6'
    implementation 'com.google.firebase:firebase-storage:16.0.5'
    implementation 'com.google.firebase:firebase-config:16.1.3'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
}
apply plugin: 'com.google.gms.google-services'

还请添加以下现在必须的依赖项:

implementation 'com.google.firebase:firebase-core:16.0.6'

您的应用 gradle 文件现在必须明确com.google.firebase:firebase-core列为 Firebase 服务的依赖项才能按预期工作。

在您的顶级build.gradle文件中,请确保拥有最新版本的 Google 服务插件:

classpath 'com.google.gms:google-services:4.2.0'

推荐阅读