How to resolve dependency conflict created by gradle plugin?

Viewed 7430

I am attempting to update my app for Android O, and in doing so need to update to support library 26.

My compileSdkVersion is 26, targetSdkVersion 26, buildToolsVersion 26.0.1, and support library version is 26.0.1, and play services/firebase messaging is 11.0.4. I'm using Android Studio 3.0 b2, and the android gradle plugin 3.0.0-beta2. It appears that this version is much more sensitive to support library conflicts.

I've had to manually exclude the support dependencies to resolve conflicts since play services and firebase link against older versions of the support libraries:

implementation("com.google.android.gms:play-services-auth:$playServicesVersion",{
    exclude group: 'com.android.support'
})

implementation("com.google.android.gms:play-services-identity:$playServicesVersion",{
    exclude group: 'com.android.support'
})

implementation("com.google.android.gms:play-services-base:$playServicesVersion",{
    exclude group: 'com.android.support'
})

implementation("com.google.android.gms:play-services-analytics:$playServicesVersion",{
    exclude group: 'com.android.support'
})

implementation("com.google.firebase:firebase-messaging:$playServicesVersion",{
    exclude group: 'com.android.support'
})

implementation("com.google.firebase:firebase-analytics:$playServicesVersion",{
    exclude group: 'com.android.support'
})

This fixes all my dependency conflicts except one.

Google Play Services/Firebase requires the use of a google-services gradle plugin to parse the generated .json file and include the necessary keys/secrets in the app. My build.grade has a buildscript block like so:

buildscript {
    repositories {
        maven { url "https://maven.google.com" }
        jcenter()
    }

    dependencies {
        classpath "com.google.gms:google-services:3.1.0"
    }
}

and at the end of the script, I apply the plugin. With the apply and classpath commented out, everything compiles properly. However it appears that the google-services 3.1.0 adds a dependency on support library version 25.2.0, and I haven't been able to figure out how to override it. The message is:

  • What went wrong: Execution failed for task ':app:preDevelopmentDebugBuild'.

    Android dependency 'com.android.support:support-v4' has different version for the compile (25.2.0) and runtime (26.0.1) classpath. You should manually set the same version via DependencyResolution

Note that I can't even downgrade to support library 25.4.0, as I get the same error (just replace 26.0.1 in the message above with 25.4.0). The only version that works is 25.2.0

Running ./gradlew app:dependencies with the classpath dependency included, gives me this:

compile - Compile dependencies for 'main' sources (deprecated: use 'implementation' instead).
\--- com.google.firebase:firebase-core:11.0.4
     \--- com.google.firebase:firebase-analytics:[11.0.4] -> 11.0.4
          +--- com.google.firebase:firebase-analytics-impl:[11.0.4] -> 11.0.4
          |    +--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4
          |    |    \--- com.android.support:support-v4:25.2.0
          |    |         +--- com.android.support:support-compat:25.2.0
          |    |         |    \--- com.android.support:support-annotations:25.2.0
          |    |         +--- com.android.support:support-media-compat:25.2.0
          |    |         |    +--- com.android.support:support-annotations:25.2.0
          |    |         |    \--- com.android.support:support-compat:25.2.0 (*)
          |    |         +--- com.android.support:support-core-utils:25.2.0
          |    |         |    +--- com.android.support:support-annotations:25.2.0
          |    |         |    \--- com.android.support:support-compat:25.2.0 (*)
          |    |         +--- com.android.support:support-core-ui:25.2.0
          |    |         |    +--- com.android.support:support-annotations:25.2.0
          |    |         |    \--- com.android.support:support-compat:25.2.0 (*)
          |    |         \--- com.android.support:support-fragment:25.2.0
          |    |              +--- com.android.support:support-compat:25.2.0 (*)
          |    |              +--- com.android.support:support-media-compat:25.2.0 (*)
          |    |              +--- com.android.support:support-core-ui:25.2.0 (*)
          |    |              \--- com.android.support:support-core-utils:25.2.0 (*)
          |    +--- com.google.firebase:firebase-iid:[11.0.4] -> 11.0.4
          |    |    +--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4 (*)
          |    |    \--- com.google.firebase:firebase-common:[11.0.4] -> 11.0.4
          |    |         +--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4 (*)
          |    |         \--- com.google.android.gms:play-services-tasks:[11.0.4] -> 11.0.4
          |    |              \--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4 (*)
          |    +--- com.google.firebase:firebase-common:[11.0.4] -> 11.0.4 (*)
          |    \--- com.google.android.gms:play-services-tasks:[11.0.4] -> 11.0.4 (*)
          +--- com.google.android.gms:play-services-basement:[11.0.4] -> 11.0.4 (*)
          \--- com.google.firebase:firebase-common:[11.0.4] -> 11.0.4 (*)
2 Answers
Related