All com.android.support libraries must use the exa

2019-09-24 02:01发布

问题:

I found a error problem in build.gradle. Have a message to me "All com.android.support libraries must use the exact same version specification (mixing version can lead to runtime crashes). And there is a red line on the bottom of "implementation 'com.android.support:appcompat-v7:28.0.0'".I don't know where I went wrong.

Thank you

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.android.support:design:28.0.0"
implementation "com.android.support:design:28.0.0"
implementation 'com.android.support:palette-v7:28.0.0'
implementation "com.android.support:cardview-v7:28.0.0"
implementation "com.android.support:recyclerview-v7:28.0.0"

//Firebase Dependencies
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-firestore:18.0.1'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.firebase:firebase-ads:17.1.3'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-appindexing:17.1.0'
implementation 'com.google.firebase:firebase-ads:17.2.0'

implementation 'com.google.android.gms:play-services-ads:17.2.0'

implementation 'com.artjimlop:altex-image-downloader:0.0.4'
implementation 'com.yalantis:ucrop:2.2.0'

implementation 'com.github.danimahardhika:cafebar:1.3.1'
implementation 'com.github.qiugang:EditTag:v1.2.4-beta2'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.airbnb.android:lottie:2.6.0'
implementation 'com.github.chyrta:AndroidOnboarder:0.7'

//Error Fixer
implementation 'com.android.support:multidex:1.0.3'

implementation 'com.android.support:support-vector-drawable:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

回答1:

You must be seeing red line like this right? hover your mouse pointer on red line and you will see dialog like this. find which libraries are still old (in my case it was cardview) add that library's latest version in gradle and your issue may be solved.

If still it doesn't then I am seeing that you are using old Firebase libraries, update them to latest too.



回答2:

The error message is pretty clear, "All com.android.support libraries must use the exact same version specification". For example, you have this:

implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.7'

You are trying to build 2 different versions, 16.0.1 and 16.0.7, of the same library. This can lead to runtime crashes. Choose which version you want to keep and delete the other. For example, if you want the version 16.0.7, replace these two lines with:

implementation 'com.google.firebase:firebase-core:16.0.7'


回答3:

Your gradle dependencies require rework:

  1. Clean the duplicate dependencies and add each line only once!

Lines:

  • implementation 'com.android.support:appcompat-v7:28.0.0'
  • implementation "com.android.support:design:28.0.0"

are twice. Keep each one only once!

  1. Use only one version definition of each library. Firebase core has import of two different versions:
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.7'

Select one of the two lines.

  1. Depenencies of your dependencies should not have different versions. You have many libraries that use other versions of com.android.support components, which can cause this error.

For example:

  • 'com.artjimlop:altex-image-downloader:0.0.4' use com.android.support:appcompat-v7:23.1.0 see here

  • 'com.yalantis:ucrop:2.2.0' use com.android.support:appcompat-v7:24.2.0 see here

  • 'com.github.danimahardhika:cafebar:1.3.1' use com.android.support:design and com.android.support:cardview-v7 see here

  • 'com.github.qiugang:EditTag:v1.2.4-beta2' use com.android.support:recyclerview-v7 and com.android.support:appcompat-v7 see here

  • etc the list goes on for almost all 3rd party github libraries.

You can use the following configuration in order to exclude all that dependencies.

configurations {
  all*.exclude module: "appcompat-v7"
  all*.exclude module: "recyclerview-v7"
  all*.exclude module: "design"
  all*.exclude module: "cardview-v7"
  // ... etc in case there are extra dependencies
}

or even better you can get through each dependency and exclude the exact libraries that cause the duplication:

ie. for 'com.artjimlop:altex-image-downloader:0.0.4' you should change the implementation 'com.artjimlop:altex-image-downloader:0.0.4' with:

implementation ('com.artjimlop:altex-image-downloader:0.0.4') {
   exclude group: 'com.android.support', module: 'appcompat-v7'
   // for more than one just add it in a new line ie.
   // exclude group: '<first part till : symbol>', module: '<second part between : symbol and version>'
}

Read this article here if you want to dig further regarding dependencies of dependencies issue.