Android dependency has different version for compilation and runtime

After updating Android Studio from Canary 3 to Canary 4, the following error occurs during build.

The Android dependency com.android.support:support-support-v4 has a different version for the compilation path (25.2.0) and runtime (26.0.0-beta2). You must manually install the same version through DependencyResolution.

I performed a full search on the entire project, and version 25.1.0 is not used here.

App-build.gradle

 android { compileSdkVersion 26 buildToolsVersion '26.0.0' defaultConfig { applicationId "com.xxx.xxxx" minSdkVersion 14 targetSdkVersion versionCode 1 versionName "1.0" multiDexEnabled true } buildTypes { debug { debuggable true } release { debuggable false minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } lintOptions { abortOnError false } }} dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'junit:junit:4.12' implementation project(':core') implementation com.google.android.gms:play-services-gcm:9.0.0' implementation('com.crashlytics.sdk.android:crashlytics: 2.6.5@aar ') { transitive = true } implementation 'com.android.support:multidex:1.0.1' implementation 'com.flurry.android:analytics:7.0.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0' implementation 'com.jakewharton:butterknife:8.6.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' } 

Library-build.gradle:

 apply plugin: 'com.android.library' android { compileSdkVersion 26 buildToolsVersion '26.0.0' defaultConfig { minSdkVersion 14 targetSdkVersion versionCode 1 versionName "1.0" } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation files('libs/model.jar') testImplementation 'junit:junit:4.12' implementation 'com.android.support:percent:26.0.0-beta2' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' implementation 'com.android.support:support-core-utils:26.0.0-beta2' implementation 'com.squareup.retrofit2:retrofit:2.0.2' implementation 'com.squareup.picasso:picasso:2.4.0' implementation 'com.squareup.retrofit2:converter-gson:2.0.2' implementation 'com.squareup.okhttp3:logging-interceptor:3.2.0' implementation 'uk.co.chrisjenx:calligraphy:2.2.0' implementation 'com.google.code.gson:gson:2.2.4' implementation 'com.android.support:design:26.0.0-beta2' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1' } 

Note: The project was built in Canary 3

+99
android android-studio android-gradle build.gradle android-gradle-plugin
source share
15 answers

Use this code in your buildscript (build.gradle root):

 subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "version which should be used - in your case 26.0.0-beta2" } } } } 
+127
source share

I had the same error as my problem. In my library, instead of using compilation or implementation, I use "api". So at the end my dependencies:

 dependencies { api fileTree(dir: 'libs', include: ['*.jar']) api files('libs/model.jar') testApi 'junit:junit:4.12' api 'com.android.support:percent:26.0.0-beta2' api 'com.android.support:appcompat-v7:26.0.0-beta2' api 'com.android.support:support-core-utils:26.0.0-beta2' api 'com.squareup.retrofit2:retrofit:2.0.2' api 'com.squareup.picasso:picasso:2.4.0' api 'com.squareup.retrofit2:converter-gson:2.0.2' api 'com.squareup.okhttp3:logging-interceptor:3.2.0' api 'uk.co.chrisjenx:calligraphy:2.2.0' api 'com.google.code.gson:gson:2.2.4' api 'com.android.support:design:26.0.0-beta2' api 'com.github.PhilJay:MPAndroidChart:v3.0.1' } 

More information about the "api", "implementation" can be found in this link fooobar.com/questions/23377 / ...

+80
source share

You should be able to see exactly which dependency gradle -q dependencies odd version as a transitive dependency by running the correct gradle -q dependencies for your project, as described here:

https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies

After you track what it includes, you can add an exception to this particular dependency in your Gradle file with something like:

 implementation("XXXXX") { exclude group: 'com.android.support', module: 'support-compat' } 
+22
source share

After a lot of time and getting help from a friend who knows about android much more than me: app / build.gradle

 android { compileSdkVersion 27 // org.gradle.caching = true defaultConfig { applicationId "com.cryptoviewer" minSdkVersion 16 targetSdkVersion 23 versionCode 196 versionName "16.83" // ndk { // abiFilters "armeabi-v7a", "x86" // } } 

and dependencies

 dependencies { implementation project(':react-native-camera') //... implementation "com.android.support:appcompat-v7:26.1.0" // <= YOU CARE ABOUT THIS implementation "com.facebook.react:react-native:+" // From node_modules } 

in build.gradle

 allprojects { //... configurations.all { resolutionStrategy.force "com.android.support:support-v4:26.1.0" } 

in gradle.properties

 android.useDeprecatedNdk=true android.enableAapt2=false org.gradle.jvmargs=-Xmx4608M 
+16
source share

For me, the answer was also to add this to my build.gradle file:

 configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "26.1.0" } } } 

In my case, it was necessary to enclose the resolution strategy in the configurations.all {.. } block. I placed the configurations.all block directly in my app/build.gradle (that is, the configurations.all file was not embedded in anything else)

+5
source share

This worked for me:

Add the following line to app/build.gradle in the dependencies section:

 implementation "com.android.support:appcompat-v7:27.1.0" 

or :27.1.1 in my case

+4
source share

I decided this, following what Eddie mentioned above,

  resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "26.1.0" } } 
+2
source share

Switching my conflicting dependencies from implementation to API does the trick. Here is a good mindorks article explaining the difference.

https://medium.com/mindorks/implementation-vs-api-in-gradle-3-0-494c817a6fa

Edit:

Here are my dependency resolutions as well

  subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex')) { details.useVersion "28.0.0" } if (details.requested.group == 'com.google.android.gms' && details.requested.name.contains('play-services-base')) { details.useVersion "15.0.1" } if (details.requested.group == 'com.google.android.gms' && details.requested.name.contains('play-services-tasks')) { details.useVersion "15.0.1" } } } } 
+2
source share

Look in your library projects to make compileSdkVersion and targetSdkVersion version at the same level as your application

 android { compileSdkVersion 28 defaultConfig { consumerProguardFiles 'proguard-rules.txt' minSdkVersion 14 targetSdkVersion 28 } } 

also make all dependencies on the same level

+2
source share

If someone gets this addiction problem in 2019, upgrade Android Studio to version 3.4 or later

+2
source share

I will comment //api 'com.google.android.gms:play-services-ads:15.0.1' it worked for me after synchronization

+1
source share

Just add these lines to your build.gradle file

resolutionStrategy.force "com.android.support:support-media-compat:26.0.0-beta2"

resolutionStrategy.force "com.android.support:support-v4:26.0.0-beta2"

+1
source share

I solved this problem by updating my gradle dependency in the file android / build.gradle: classpath 'com.android.tools.build:gradle{.3.1' (I previously worked on version 3.2.

+1
source share

Add this code to the project-level build.gradle file.

 subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "version which should be used - in your case 28.0.0-beta2" } } } } 

Code example:

 // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:3.2.0' classpath 'io.fabric.tools:gradle:1.31.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir } subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.android.support' && !details.requested.name.contains('multidex') ) { details.useVersion "28.0.0" } } } } 
0
source share

Replace the hardcode version with a + example:

 implementation 'com.google.android.gms:play-services-base:+' implementation 'com.google.android.gms:play-services-maps:+' 
-7
source share

All Articles