'Could not find com.google.firebase:firebase-analytics:
I am new to firebase and try to implement firebase in next project. I included dependencies as below but it shows the above error. I would be grateful if anyone can provide information.
My builder.gradle(app)files is as follows:
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'
Solution 1:[1]
When you integrate Firebase into your app, you must choose one of two ways of adding dependencies, according to the documentation. You can either choose to use specific versions of each dependency, like this:
implementation 'com.google.firebase:firebase-analytics:18.0.0'
implementation 'com.google.firebase:firebase-firestore:22.0.0'
Or, you can use the Firebase BoM to choose them for you, based on a single BoM version that applies specific compatible versions for you:
// 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'
It looks like you tried to use the BoM, but didn't add a line for choosing the platform.
Solution 2:[2]
You need to specify explicit version numbers like you did it for the other dependencies. For example:
implementation 'com.google.firebase:firebase-analytics:18.0.0'
implementation 'com.google.firebase:firebase-firestore:22.0.0'
Here you can find more information about the firebase versions --> https://firebase.google.com/support/release-notes/android
Solution 3:[3]
I was getting the same error when implementing some Compose UI tests. For me the problem was that the androidTestImplementation
configuration did not actually have the firebase dependency.
Solved by adding
androidTestImplementation("com.google.firebase:firebase-messaging-ktx")
to the build.gradle
, along with the previously present
implementation("com.google.firebase:firebase-messaging-ktx")
This does not actually make sense, according to this post. Worked for me though.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Doug Stevenson |
Solution 2 | J. Hegg |
Solution 3 | Jakub Mina?ík |