-2

I have following dependencies in my app-level build.gradle file

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.1'
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.android.volley:volley:1.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.android.support:cardview-v7:27.0.2'
}

These works fine without any error. But, When I try to put a new third party dependency of CircleImageView implementation 'de.hdodenhof:circleimageview:2.2.0', the gradle build fails and there is error on implementation 'com.android.support:appcompat-v7:27.0.2' line saying All com.android.support libraries must use the exact same version.... I am wondering how this third party library creating problem in support libraries. What is wrong there?

Strooks
  • 183
  • 1
  • 10
  • Use this `implementation 'com.android.support:appcompat-v7:27.1.1'` – AskNilesh Oct 08 '18 at 12:09
  • @NileshRathod still there is an error – Strooks Oct 08 '18 at 12:10
  • Because that third party library internally also uses the app compat library and because the version used by your project is different from the library version, it gives the error. But your app should work fine even with the error. – Vivek Mishra Oct 08 '18 at 12:11
  • 1
    Also update dependencies for cardview `implementation 'com.android.support:cardview-v7:27.1.1'` – AskNilesh Oct 08 '18 at 12:11
  • 1
    @NileshRathod Thanks, worked fine! – Strooks Oct 08 '18 at 12:12
  • 1
    Possible duplicate of [All com.android.support libraries must use the exact same version specification](https://stackoverflow.com/questions/42374151/all-com-android-support-libraries-must-use-the-exact-same-version-specification) – Nick Cardoso Oct 08 '18 at 12:45

4 Answers4

2

That library is implementing support libraries as well, but different versions. Specifically, it uses the support-annotations 27.1.0 library.

There are two things you can do.

  1. Update your dependencies. 27.0.2 is outdated. 27.1.0 is as well, but less so.
  2. Exclude that library from your implementation and implement it yourself:

    implementation ("de.hdodenhof:circleimageview:2.2.0") {
        exclude group: "com.android.support" module: "support-annotations"
    }
    implementation 'com.android.support:support-annotations:27.1.1'
    

    You should update all your support dependencies to 27.1.1.

TheWanderer
  • 16,775
  • 6
  • 49
  • 63
1

The third party library internally uses the app compat library and because the version used by project is different from the library version, it gives the error. Updating appcompat, design and cardview dependencies to version 27.1.1 worked fine as follows.

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:27.1.1'
  implementation 'com.android.support.constraint:constraint-layout:1.0.2'
  implementation 'com.android.support:design:27.1.1'
  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.android.volley:volley:1.1.1'
  implementation 'com.github.bumptech.glide:glide:4.8.0'
  implementation 'com.android.support:cardview-v7:27.1.1'
  implementation 'de.hdodenhof:circleimageview:2.2.0'
}
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Strooks
  • 183
  • 1
  • 10
  • 1
    [It’s OK to Ask and Answer Your Own Questions](https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/) – AskNilesh Oct 08 '18 at 12:24
  • @Mohsen I have to wait 2 days for accepting my own answer – Strooks Oct 08 '18 at 12:27
  • Seems this is what TheWanderer told you in his answer. Answering your own question should be reserved for questions that have no duplicates on SO and for new information not to state which advice you followed – Nick Cardoso Oct 08 '18 at 12:45
0

The support libraries should have the same version as the other dependencies which are related.

Change them to v 27.1.1 (The point is they should have the same version):

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'

And then if you saw any errors which points to "should have same version", run :

./gradlew dependencies

To see which library is using old version.

Mostly, it can be fixed by adding the updated version of the library (same as the support library) in your build.gradle dependencies.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108
  • 2
    Why 28? The library uses 27.1.1 and OP uses 27.0.2, which means their compile and target SDK are set to 27. This would cause more problems. And `support-media-compat` has nothing to do with CircleImageView. – TheWanderer Oct 08 '18 at 12:16
  • 1
    They _should_ use the same version. Using 28.0.0 means they _aren't_. – TheWanderer Oct 08 '18 at 12:19
0

If you want all support libraries including third party libraries internally use the same support library version, then add below code in your project level gradle

ext {
    support_library_version = '27.1.1'
}

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->

            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex')) {
                details.useVersion "$support_library_version"
            }
        }
    }
}