Firebase 未解析参考

rad*_*dob 4 android kotlin firebase

我已经通过包含的助手实现了 Firebase 数据库。它添加到我的 gradle 依赖项中implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'

在那之后,我无法构建项目(解决方案是将impelentation更改为kapt)

我的gradle看起来像:

dependencies {
        kapt 'com.google.firebase:firebase-database:16.0.1:15.0.0'
        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.constraint:constraint-layout:1.1.3'
        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.android.support:design:28.0.0'
    }
Run Code Online (Sandbox Code Playgroud)

然后,我需要检索我的数据库的一个实例

class AppActivity : AppCompatActivity() {

    val manager = supportFragmentManager


    var database = FirebaseDatabase.getInstance()
Run Code Online (Sandbox Code Playgroud)

及其错误, 未解决的参考:FirebaseDatabase

我试图处理它,但它似乎超出了我的范围。

各位大侠,知道是什么原因吗?

小智 5

我今天面临同样的问题,我通过添加下一行来解决它

implementation 'com.google.firebase:firebase-database-ktx:19.2.1'
Run Code Online (Sandbox Code Playgroud)

但请注意,我使用的是更高版本。Firebase 的

implementation 'com.google.firebase:firebase-database:19.2.1'`
Run Code Online (Sandbox Code Playgroud)

当您使用 firebase-database:16.0.1:15.0.0 时,您可能需要添加下一行

implementation 'com.google.firebase:firebase-database-ktx:16.0.1:15.0.0'
Run Code Online (Sandbox Code Playgroud)

我希望它也对你有用。

罗摩