3

My android Studio shows this error.

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 26.1.0. Examples include com.android.support:animated-vector-drawable:27.1.1 and com.android.support:support-media-compat:26.1.0 less... (Ctrl+F1) There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion).

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.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'
    implementation 'com.google.firebase:firebase-core:15.0.0'
Yesudass Moses
  • 1,841
  • 3
  • 27
  • 63
  • 3
    it themes like `com.google.firebase:firebase-core:15.0.0` depends on older support library. There already is `15.0.2` version released. Probably it is based on the latest support library. Meanwhile, you have 2 more options - ignore this message (it is not an error in fact, but a warning), or downgrade your used support libs version to `26.1.0` – Vladyslav Matviienko May 16 '18 at 05:42
  • Thanks... I upgraded to firebase 15.0.2 and downgraded api level to 26. Now it looks good. – Yesudass Moses May 16 '18 at 05:44
  • 1
    I'll make it an answer – Vladyslav Matviienko May 16 '18 at 05:46
  • 3
    You should not downgrade support library version as it is not a solution. Instead you can exclude support group from firebase. – Kruti Parekh May 16 '18 at 05:57
  • @parekhkruti26 could you share a link of how to do that, or post an answer? I suffer from this problem same as the question owner, and your solution themes a correct way. – Vladyslav Matviienko May 16 '18 at 05:58
  • Sure, just a minute. – Kruti Parekh May 16 '18 at 05:59
  • 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) – Grimthorr Jun 01 '18 at 14:27

3 Answers3

5

Instead of downgrading or excluding the support library, you can solve the problem by overriding the support library. You can override the support library by adding the dependency which is in the error:

implementation "com.android.support:animated-vector-drawable:27.1.1"

For argumentation about this answer, you can see the following issues in Firebase:

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • so basically if we directly use latest version of the lib, it will override firebase-dependance version, right? – Vladyslav Matviienko May 16 '18 at 06:01
  • That's right. But it's only work for Firebase. Haven't test it with another library. – ישו אוהב אותך May 16 '18 at 06:03
  • It may also cause `:app:transformDexArchiveWithExternalLibsDexMergerForDebug` runtime exception. So it is better to exclude and then add as a safety measure. – Kruti Parekh May 16 '18 at 06:08
  • If it causes the above exception then you need to do as specified in the answer here: https://stackoverflow.com/questions/50182756/multiple-dex-files-define-lcom-google-android-gms-internal-measurement-zzabn – Peter Haddad May 16 '18 at 06:09
  • @parekhkruti26 the problem probably can be solved by PeterHaddad answer. Imho, excluding is doing exactly like overriding but overriding do it beautifully. – ישו אוהב אותך May 16 '18 at 06:22
  • New google-services plugin has some issues when using multi-module, data-binding (others also which I don't know). [Issue tracker link](https://issuetracker.google.com/issues/79122163) – Kruti Parekh May 16 '18 at 06:38
3

It themes like com.google.firebase:firebase-core:15.0.0 depends on older support library varsion (26.1.0).
There already is 15.0.2 version released, so you could try to:

  • use 15.0.2 version of firebase core. Probably it is based on latest support lib
  • ignore this message, as it is a warning, not an error, and probably your app would work fine with it. (not recommended, but could work)
  • downgrade your used support libs version to 26.1.0 so they are the same version. At least until google releases firebase based on the latest support lib version. (recommended way if #1 didn't work)
Vladyslav Matviienko
  • 10,610
  • 4
  • 33
  • 52
1

When you run ./gradlew :app:dependencies, you come to know the transitive dependencies of libraries one has included in their gradle.

From that hierarchy view, one can find out which libraries are depending on older versions and exclude them in gradle as shown below:

 exclude group:'com.android.support'//as an example support library is excluded

As far as this question is concerned, it can be done like this:

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.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'
implementation ('com.google.firebase:firebase-core:15.0.2'){
    exclude group:'com.android.support'
}

Here support library is excluded as firebase core was depending on older versions, creating a conflict.

NOTE:

If your dependencies don't include the libraries that you have excluded but the dependency from which you have excluded needs it, you can add the excluded library in gradle with your compatible version.

Kruti Parekh
  • 1,271
  • 9
  • 21