Android dependency com.google.firebase:firebase-co

2019-07-21 00:41发布

问题:

this is my Project Gradle dependencies

classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.google.gms:google-services:3.0.0'
classpath "io.realm:realm-gradle-plugin:4.2.0"
classpath 'com.google.firebase:firebase-plugins:1.1.1'

this is my App Gradle dependencies

implementation 'com.google.android.gms:play-services-ads:11.4.2'
implementation 'com.google.firebase:firebase-core:11.4.2'
implementation 'com.google.android.gms:play-services-base:11.4.2'
implementation 'com.google.firebase:firebase-messaging:11.4.2'

Also i have change implementation to api ... the error still appears

回答1:

add below dependency into app level gradle file ..

    implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.google.firebase:firebase-core:15.0.2'
implementation 'com.google.android.gms:play-services-base:15.0.1'
implementation 'com.google.firebase:firebase-messaging:15.0.2'


回答2:

You just need to change your google lib version into the stable version. you are using an unstable version. Use following

implementation 'com.google.android.gms:play-services-location:12.0.0'
implementation 'com.google.android.gms:play-services-places:12.0.0'
implementation 'com.google.firebase:firebase-messaging:12.0.0'
implementation 'com.google.firebase:firebase-core:12.0.0'

and use this classpath

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

and remove the firebase classpath from the project

classpath 'com.google.firebase:firebase-plugins:1.1.1'


回答3:

Where do you apply the google-services plugin? https://developers.google.com/android/guides/google-services-plugin#introduction requires you apply it at the bottom of your app's build.gradle to avoid dependency collisions similar to the one you are describing.

You can also run ./gradlew :app:dependencies to see if you have any dependency collisions which lead to multiple versions of firebase-core.