0

I'm aware this question has been asked before, but I'm new to Android and Java in general. I've gone through the previous questions and tried various solutions but never seems to work.

I'm getting the "all com.android.support libraries must use the exact same version specification" warning in my app gradle file. My dependencies are:

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.tberwick.hishhash"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:animated-vector-drawable:26.1.0'
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 "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"

implementation 'com.android.support:recyclerview-v7:26.1.0'

implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
implementation "android.arch.lifecycle:extensions:1.0.0"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
}

The error I was receiving was

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.0.1, 26.1.0. Examples include com.android.support:animated-vector-drawable:27.0.1 and com.android.support:recyclerview-v7:26.1.0 less... (⌘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.)

So I added in the specific line implementation 'com.android.support:animated-vector-drawable:26.1.0' but I still see the same error after syncing.

I've noticed that if I view my .idea/libraries folder that the app-compact and vector-drawable xml files in there get created for version 27.0.1 even though my versions are specified as 26.1.0

As I say I know this has been asked before but what I believe the solution should be based on those answers doesn't seem to work. I don't think I should use the versions 27.0.1 either as doing this complains about my targetSdkVersion (which I do understand)

Zoe
  • 27,060
  • 21
  • 118
  • 148
TommyBs
  • 9,354
  • 4
  • 34
  • 65
  • @Zoe I've looked through that question and it seems to imply that what I've already tried as a solution should have worked. That's why I posted a new question – TommyBs Jan 23 '18 at 20:15

1 Answers1

2
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'

Using a variable version like this is risky, in that all of a sudden your build can break, just because Facebook updated their library.

The current latest Facebook SDK version (4.29.0) wants to use 27.0.1 of the support libraries. Gradle uses the latest version requested by any dependency by default, as that is usually the safest course of action.

The best solution is to move to 27.0.1 for the support libraries, which in turn will trigger you to raise your compileSdkVersion to 27.

If something else is forcing you to use 26.1.0... there does not appear to be a Facebook SDK that specifically supports that version, based on a casual inspection of the POM files for their SDK artifacts.

You could replace the above line by:

implementation 'com.facebook.android:facebook-android-sdk:4.28.0'

4.28.0 of the Facebook SDK wants 25.3.1 of the support libraries, and so Gradle will tend to use the 26.1.0 that you are requesting. However:

  • You may get a variation of the original error, complaining about a mix of 26.1.0 and 25.3.1. That's where the solution that you tried applying — manually requesting the offending artifact for 26.1.0 — will help. You can use that approach to raise the version number that Gradle uses, but not lower it.

  • It is conceivable that the Facebook SDK will be cranky when using 26.1.0 of the support libraries.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks, upgrading that to version 27 worked. Though I copied the Facebook SDK code from their docs. I've set it to 4.29.0 . I'm guessing the targetSDK version though will now effect how many devices can install my app or should it be covered by the minSdkVersion? – TommyBs Jan 23 '18 at 20:27
  • 1
    @TommyBs: "I'm guessing the targetSDK version though will now effect how many devices can install my app" -- no. "should it be covered by the minSdkVersion?" -- yes. `targetSdkVersion` is "this is the version of Android that I was thinking of when I wrote this code", and it is used to help with forwards compatibility, when your app winds up running on newer Android devices in the future. – CommonsWare Jan 23 '18 at 20:39