5

After updating targetSdkVersion to 27 I got this error message.

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.0.2, 25.2.0. Examples include com.android.support:animated-vector-drawable:27.0.2 and com.android.support:support-media-compat:25.2.0

I understand that I should update com.android.support:support-media-compat but I dont know how because I am not using it in build.gradle , I tried to update SDK tools but the problem is still remaining . bellow is build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.ex"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.google.android.gms:play-services-ads:11.6.2'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.github.bloder:magic:1.1'
    implementation 'com.android.support:recyclerview-v7:27.0.2'
    implementation 'com.android.support:cardview-v7:27.0.2'
}
InsaneCat
  • 2,115
  • 5
  • 21
  • 40
Chawkii
  • 221
  • 5
  • 13

6 Answers6

6

I have checked manually the libraries in project -> .myidea-> libraries then I found that I have two libraries using the old version :

com_android_support_support_media_compat_25_2_0 com_android_support_support_v4_25_2_0

then just by adding this line in builde.gradle

implementation 'com.android.support:support-v4:27.0.2'

The error is gone now.

Chawkii
  • 221
  • 5
  • 13
2

I encountered the exact same problem. You are not using in your build.graddle but some library that you included in your build.graddle is using. Therefore, you need to override them, which are pointed in warning, in your build.graddle

Ergin Ersoy
  • 890
  • 8
  • 28
0

I have gotten this error before. Try clicking build on Android Studio Toolbar.

  1. Clean Build
  2. After Step 2, Click Rebuild Project.

Update If not, try explicitly adding implementation com.android.support:support-media-compat:27.0.2 to the build

martinomburajr
  • 1,235
  • 14
  • 29
0

What you are dealing with appears to be transitive dependencies. In other words just as you use gradle so you don't have to re-invent the wheel the maker of the dependency you are using also uses dependencies. It appears the problem is with this dependency 'com.github.bloder:magic:1.1' because it depends on 'com.android.support:appcompat-v7:23.1.1'. I found this out by visiting the repository pom description for blogger magic. In android studio I could also have also clicked on the gradle tab on the right and found one of the dependency task and found the conflict this way. Now that we know the problem excluding a transitive dependency may help checking to see if all dependencies are up to date may help or not using blogger magic at all may help. This problem is difficult, I know. Just hope this helps.

Pomagranite
  • 696
  • 5
  • 11
  • this seems to be so difficult , by the way , this is actually solving the problem : //noinspection GradleCompatible but I don't understand what does it do – Chawkii Dec 14 '17 at 15:07
  • I feel your pain. Transitive dependencies are difficult. //noinspection seems to be telling the compiler I know I have version conflicts but go ahead and compile anyway. So it may work on your device. It may work on all devices. I suggest you look for updates on the out of date dependency in the future and update build.gradle at that time. Was I right about bloder magic? Android studio>file>project structure>dependencies will show all imported jar files gradle pulled in for you including transitive dependencies – Pomagranite Dec 14 '17 at 15:54
  • no pain bro , I found out the solution , check my answer – Chawkii Dec 14 '17 at 15:56
  • your answer is right by the way , there is some transitive dependencies , for my case its 2 libraries : com_android_support_support_media_compat_25_2_0 com_android_support_support_v4_25_2_0 . So I tried to implement 'com.android.support:support-v4:27.0.2' and it worked , now the folder libraries containes 2 new libraries which are com_android_support_support_media_compat_27_0_2 com_android_support_support_v4_27_0_2 , and the old versions still in the folder too – Chawkii Dec 14 '17 at 16:00
  • I am glad you got it to work. In the future if you see crashes on google analytics check for new versions on all your dependencies. A dependency is usually backward compatible by the way. – Pomagranite Dec 14 '17 at 16:16
-1

I encountered similar problem when updated the gradle. I implicitly declared the error written support library. I had to perform this implicitly for 3 more support libraries. This error does not solve by implicitily declaring a support library. If u want to solve the problem immediately, then replace all 27.0.2 to 25.2.0 in com.android.support.* libraries.

T. Gibbons
  • 4,919
  • 2
  • 15
  • 32
-1

As you already seen the all answers and comments above but this answer is to clear something which a new developer might not get easily.

./gradlew -q dependencies app:dependencies --configuration compile

The above line will save your life with no doubt but how to get the exact point from the result of above line.

When you get the all dependency chart or list from the above command then you have to search the conflicting version number which you are getting in your code. please see the below image.

enter image description here

in the above image you can see that 23.4.0 is creating the problem but this we not able to find in our gradle file. So now this version number(23.4.0) will save us. When we have this number then we will find this number in the result of above command result and directly import that dependency directly in our gradle file. Please see the below image to get the clear view.

you can clearly see that com.android.support:cardview-v7:23.4.0 and com.android.support:customtabs:23.4.0 are using the version which is creating the problem. Now just simply copy those line from dependency list and explicitly use in our gradle file but with the updated version link

implementation "com.android.support:cardview-v7:26.1.0" implementation "com.android.support:customtabs:26.1.0"

Please refer this to see the original answer https://stackoverflow.com/a/49169228/4156595

anoop ghildiyal
  • 821
  • 10
  • 18
  • From Gradle version 3.0. compile has been replaced by implementation. If anyone using the latest one. use this. ./gradlew -q dependencies app:dependencies --configuration debugAndroidTestCompileClasspath – Nizamudeen Sherif May 15 '18 at 08:34