首页 > 解决方案 > 找不到 com.google.firebase:firebase-analytics:

问题描述

我是firebase的新手,并尝试在下一个项目中实施firebase。我包含了如下依赖项,但它显示了上述错误。如果有人能提供信息,我将不胜感激。

我的 builder.gradle(app) 文件如下:

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'

    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-firestore'

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
apply plugin: 'com.google.gms.google-services'

标签: androidfirebase

解决方案


根据文档,当您将 Firebase 集成到您的应用中时,您必须选择两种添加依赖项的方式之一。您可以选择使用每个依赖项的特定版本,如下所示:

    implementation 'com.google.firebase:firebase-analytics:18.0.0'
    implementation 'com.google.firebase:firebase-firestore:22.0.0'

或者,您可以使用 Firebase BoM 为您选择它们​​,基于为您应用特定兼容版本的单个 BoM 版本:

    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:26.1.0')

    // versions for Firebase SDKs are chosen automatically by the BoM
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-firestore'

看起来您尝试使用 BoM,但没有添加用于选择平台的行。


推荐阅读