在集成firebase
时,我遇到了一个奇怪的问题:
implementation 'com.google.firebase:firebase-database:16.0.1:15.0.0'
并且仅添加
implementation 'com.google.firebase:firebase-database:16.0.1'
因为我们自行添加了版本号为 16.0.1
的库文件,然而在使用 Android Studio 中的 Firebase 插件连接后,它会添加一个新的带有版本号为 15.0.0
的库文件。因此这是不必要的。在你的根 build.gradle
文件中添加仓库:
allprojects {
repositories {
google()
maven { url "https://maven.google.com" }
}
}
implementation com.google.firebase:firebase-database:16.0.1
,就像许多人之前所写的那样。但是还要添加以下行:kapt com.google.firebase:firebase-database:16.0.1:15.0.0
这样Firebase就会保持“依赖正确设置”。之后
implementation com.google.firebase:firebase-database:16.0.1
kapt 'com.google.firebase:firebase-database:16.0.1:15.0.0'
添加kapt,这对我有用
将所有依赖项更新至
dependencies {
implementation "com.google.android.gms:play-services-base:16.0.1"
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
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.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.5'
}
然后进行构建 -> 清理项目,构建 -> 重新构建项目,就可以正常工作了。