I cant seem to build gradle for my app on Android Studio 3.0.1 (generate apk works). Below was the build output.
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.google.firebase:firebase-messaging' in project ':app'.
Resolved versions for app (15.0.2) and test app (12.0.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 23s
Here is the build.gradle file contents.
UPDATE 21.8.2018:
I notice in the external libraries, I have a conflict
I found out that I can generate the apk (Build APK) eventhough gradle produce the conflict error. The way to remove gradle error is to remove/comment this line:
implementation 'com.google.android.gms:play-services-places:15.0.1'
but then APK wont compile. It used to work, I realized this problem may have happened after I had to include Firebase in another project (cordova based Android app) that used the same Android Studio. This problem does not happen to my other colleague machine. How do I really solve this ? Thanks
Please post your build.gradle file. But without seeing it my guess is that you have an implementation
and testImplementation
that have different versions for com.google.firebase:firebase-messaging
Try to force the version of your firebase dependency using below configuration
android {
configurations.all {
resolutionStrategy.force 'com.google.firebase:firebase-core:16.0.1'
}
}
It looks like a transitive dependency issue. Both com.google.android.gms:play-services
and com.onesignal:OneSignal
use com.google.firebase:firebase-messaging
, but they're probably importing different versions. I'd recommend upgrade to use the latest versions of these libraries.
It seems like there are two libraries that depend on firebase-messaging library, and they're depending on different versions. To find out which ones they are, go to Terminal window in your Android Studio and run this command:
./gradlew app:dependencies
That'll show you all the dependencies in your project in a tree structure. Once you detect which libraries add the duplicate library, you can try one of these:
1) Check for the other versions of the parent dependencies in your build.gradle which both use the same version of the transitive duplicate dependency.
2) Exclude the dependency with the lower version from the parent dependency. Example:
implementation('com.example.abc:def:1.0.0') {
exclude group: 'com.google.firebase', module: 'firebase-messaging'
}
3) Enforce a fixed version w/ a resolution strategy:
configurations.all {
resolutionStrategy {
force com.google.firebase:firebase-messaging:15.0.2
}
}
Dependency OneSignal is using old version of play-service
.
You have these ways to solve this.
play-service
from OneSignal and force to use the latest- you are using. (As @gizembrh answer ). ( I dont suggest, because OneSignal's code may crash with new play-service ) play-service
version as same version of OneSignal. ( The easiest I think ) I think 3rd option best suits to you. Because you just need to downgrade your play-service version. See OneSignal build.gradle
play-service version
def playServicesVersion = '12.0.0'
implementation "com.google.android.gms:play-services-places:$playServicesVersion"
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
Also use in your project level build.gradle , use below version of google-services
. See OneSignal build.gradle
google-services version .
classpath 'com.google.gms:google-services:4.0.1'
If you do above both changes in your gradle, you will not face this error any more.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.