CCJ
CCJ

Reputation: 1719

How to use Gradle's dependency tree to resolve android support library version mismatch?

the catalyst

I upgraded Android Studio to 2.3, and Gradle plugin to 3.3

the initial problem

After updating the Gradle plugin to 3.3, I received the error "Error:The SDK Build Tools revision (23.0.3) is too low for project ':mymodulename'. Minimum required is 25.0.0"

I tried adjusting both buildToolsVersion to 25.0.2 and compileSdkVersion to 25, along with all the com.android.support dependencies (since their major version needs to match compileSdkVersion). That adjustment cleared this problem, but then I realized my app doesn't support Nougat yet so I reduced the compileSdkVersion to my targetSdkVersion of 23. The error message about build tools being too low was still gone, so I thought I was in the clear.

the first dependency error

After knocking compileSdkVersion down to 23 I tried to rebuild, and saw several errors similar to "Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'". I realized that I had forgotten to change my com.android.support dependencies such that their major version matched the lower compileSdkVersion again, so I bumped them down to 23.3.0

the second dependency error

After resolving the first dependency error, I was able to compile and run my app again. However, there was still a red squiggle beneath my first com.android.support dependency, with the error note "all com.android.support libraries must usew the exact same version specification (mixing versions can leads to runtime crashes). Found versions 24.0.0, 23.3.0. Examples include com.android.support:support-v4:24.0.0 and com.android.support:animated-vector-drawable:23.3.0"

Nothing in my build.gradle specifically references 24.0.0, behold:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion '25.0.2'


    defaultConfig {
        applicationId ...
        minSdkVersion 16
        targetSdkVersion 23
        versionCode ...
        versionName ...
    }
    buildTypes {
        debug{
            debuggable true
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions{

        //check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
    dexOptions{
        jumboMode true
    }

}

repositories {
    // You can also use jcenter if you prefer
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    //android support libs etc.
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-v13:23.3.0'
    compile 'com.android.support:mediarouter-v7:23.3.0'
    compile 'com.android.support:recyclerview-v7:23.3.0'
    //snackbar support
    compile 'com.android.support:design:23.3.0'

    //Facebook Android SDK
    compile 'com.facebook.android:facebook-android-sdk:4.7.0'
    //Facebook Audience Network SDK. Only versions 4.6.0 and above are available
    compile 'com.facebook.android:audience-network-sdk:4.7.0'

    //gplay services dependencies
    compile 'com.google.android.gms:play-services-plus:10.0.1'
    compile 'com.google.android.gms:play-services-analytics:10.0.1'
    compile 'com.google.android.gms:play-services-location:10.0.1'

    //provides Firebase Analytics
    compile 'com.google.firebase:firebase-core:10.0.1'

    //provides Google Mobile Ads SDK, a.k.a the AdMob service.
    compile 'com.google.firebase:firebase-ads:10.0.1'

    //dependencies required by the InMobi ads SDK
    compile 'com.squareup.picasso:picasso:2.5.2'

}

apply plugin: 'com.google.gms.google-services'

the dependency tree

In order to figure out where the 24.0.0 dependency was coming from, I created a dependency tree using './gradlew -q dependencies mymodulename:dependencies --configuration compile'. The output is:

    compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:23.3.0
|    +--- com.android.support:support-vector-drawable:23.3.0
|    |    \--- com.android.support:support-v4:23.3.0 -> 24.0.0
|    |         \--- com.android.support:support-annotations:24.0.0
|    +--- com.android.support:animated-vector-drawable:23.3.0
|    |    \--- com.android.support:support-vector-drawable:23.3.0 (*)
|    \--- com.android.support:support-v4:23.3.0 -> 24.0.0 (*)
+--- com.android.support:support-v13:23.3.0
|    \--- com.android.support:support-v4:23.3.0 -> 24.0.0 (*)
+--- com.android.support:mediarouter-v7:23.3.0
|    +--- com.android.support:appcompat-v7:23.3.0 (*)
|    \--- com.android.support:palette-v7:23.3.0
|         \--- com.android.support:support-v4:23.3.0 -> 24.0.0 (*)
+--- com.android.support:design:23.3.0
|    +--- com.android.support:appcompat-v7:23.3.0 (*)
|    +--- com.android.support:support-v4:23.3.0 -> 24.0.0 (*)
|    \--- com.android.support:recyclerview-v7:23.3.0
|         +--- com.android.support:support-v4:23.3.0 -> 24.0.0 (*)
|         \--- com.android.support:support-annotations:23.3.0 -> 24.0.0
+--- com.facebook.android:facebook-android-sdk:4.7.0
|    +--- com.parse.bolts:bolts-android:1.2.0
|    \--- com.android.support:support-v4:[22,23) -> 24.0.0 (*)
+--- com.facebook.android:audience-network-sdk:4.7.0
|    \--- com.google.android.gms:play-services-ads:7.8.0 -> 10.0.1
|         +--- com.google.android.gms:play-services-ads-lite:10.0.1
|         |    \--- com.google.android.gms:play-services-basement:10.0.1
|         |         \--- com.android.support:support-v4:24.0.0 (*)
|         +--- com.google.android.gms:play-services-base:10.0.1
|         |    +--- com.google.android.gms:play-services-basement:10.0.1 (*)
|         |    \--- com.google.android.gms:play-services-tasks:10.0.1
|         |         \--- com.google.android.gms:play-services-basement:10.0.1 (*)
|         +--- com.google.android.gms:play-services-clearcut:10.0.1
|         |    +--- com.google.android.gms:play-services-base:10.0.1 (*)
|         |    \--- com.google.android.gms:play-services-basement:10.0.1 (*)
|         +--- com.google.android.gms:play-services-basement:10.0.1 (*)
|         \--- com.google.android.gms:play-services-gass:10.0.1
|              \--- com.google.android.gms:play-services-basement:10.0.1 (*)
+--- com.google.android.gms:play-services-plus:10.0.1
|    +--- com.google.android.gms:play-services-base:10.0.1 (*)
|    \--- com.google.android.gms:play-services-basement:10.0.1 (*)
+--- com.google.android.gms:play-services-analytics:10.0.1
|    +--- com.google.android.gms:play-services-analytics-impl:10.0.1
|    |    +--- com.google.android.gms:play-services-base:10.0.1 (*)
|    |    \--- com.google.android.gms:play-services-basement:10.0.1 (*)
|    +--- com.google.android.gms:play-services-base:10.0.1 (*)
|    +--- com.google.android.gms:play-services-basement:10.0.1 (*)
|    \--- com.google.android.gms:play-services-tagmanager-v4-impl:10.0.1
|         +--- com.google.android.gms:play-services-analytics-impl:10.0.1 (*)
|         +--- com.google.android.gms:play-services-base:10.0.1 (*)
|         \--- com.google.android.gms:play-services-basement:10.0.1 (*)
+--- com.google.android.gms:play-services-location:10.0.1
|    +--- com.google.android.gms:play-services-base:10.0.1 (*)
|    +--- com.google.android.gms:play-services-basement:10.0.1 (*)
|    \--- com.google.android.gms:play-services-tasks:10.0.1 (*)
+--- com.google.firebase:firebase-core:10.0.1
|    \--- com.google.firebase:firebase-analytics:10.0.1
|         +--- com.google.android.gms:play-services-basement:10.0.1 (*)
|         +--- com.google.firebase:firebase-common:10.0.1
|         |    +--- com.google.android.gms:play-services-basement:10.0.1 (*)
|         |    \--- com.google.android.gms:play-services-tasks:10.0.1 (*)
|         \--- com.google.firebase:firebase-analytics-impl:10.0.1
|              +--- com.google.android.gms:play-services-basement:10.0.1 (*)
|              +--- com.google.firebase:firebase-iid:10.0.1
|              |    +--- com.google.android.gms:play-services-basement:10.0.1 (*)
|              |    \--- com.google.firebase:firebase-common:10.0.1 (*)
|              \--- com.google.firebase:firebase-common:10.0.1 (*)
+--- com.google.firebase:firebase-ads:10.0.1
|    +--- com.google.android.gms:play-services-ads:10.0.1 (*)
|    \--- com.google.firebase:firebase-analytics:10.0.1 (*)
+--- com.squareup.picasso:picasso:2.5.2
\--- com.android.support:recyclerview-v7:23.3.0 (*)

(*) - dependencies omitted (listed previously)

the questions

  1. What does the dependency tree syntax 'lib version -> different lib version' mean? Specifically, when the tree says "com.android.support:support-v4:23.3.0 -> 24.0.0", what does it mean?

  2. If there are implicit requirements for com.android.support version 24.x.x libraries in some of my other dependencies (see com.google.android.gms:play-services-basement:10.0.1 depending on com.android.support:support-v4:24.0.0), why didn't this build.gradle throw errors prior to the Android Studio, Gradle plugin, and buildToolsVersion update mentioned earlier?

  3. How can I make sure all my dependencies are compatible with compileSdkVersion 23?

Upvotes: 8

Views: 7311

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363459

Specifically, when the tree says "com.android.support:support-v4:23.3.0 -> 24.0.0", what does it mean?

It means that a library has com.android.support:support-v4:23.3.0 as nested dependency but you are just using another and higher version of the same dependencies, in this case com.android.support:support-v4:24.0.0.
In other word your project is using the com.android.support:support-v4:24.0.0

why didn't this build.gradle throw errors prior to the Android Studio, Gradle plugin, and buildToolsVersion update mentioned earlier?

Because you have updated the Gradle plugin to 3.3 that has this kind of check.

How can I make sure all my dependencies are compatible with compileSdkVersion 23?

It is quite difficult to have.
The only way is to check all dependencies, but I suggest you using:

compileSdkVersion 25
targetSdkVersion  23

In general it is a good idea to use the latest version of buildToolsVersion in any case, independently by the version of support libraries used.

Moreover. It is strongly recommended that you always compile with the latest SDK. It means that today you should use compileSdkVersion 25.

Upvotes: 7

Related Questions