Butterknife: Butterknife 8.5.1 conflicts with Android support lib 25.1.1

Created on 1 Feb 2017  Â·  6Comments  Â·  Source: JakeWharton/butterknife

I just upgraded my Android project to support Androids support lib's 25.1.1, combined with Butterknife 8.5.1. I'm receiving the conflict on the dependency 'com.android.support:support-compat' in project [project]. Resolved version for app (25.1.1) and test app (25.1.0) differ.

FYI: using butterknife 8.4 in combo with support 25.1.1 works.

Checking the dependencies, I'm seeing that

+--- com.jakewharton:butterknife:8.5.1
|    +--- com.jakewharton:butterknife-annotations:8.5.1
|    |    \--- com.android.support:support-annotations:25.1.0 -> 25.1.1
|    +--- com.android.support:support-annotations:25.1.0 -> 25.1.1
|    \--- com.android.support:support-compat:25.1.0
|         \--- com.android.support:support-annotations:25.1.0 -> 25.1.1

On penalty of feeling dumb, am I missing something here?

Got these in my build.gradle:

    compile 'com.android.support:support-core-utils:25.1.1'
    compile 'com.android.support:support-fragment:25.1.1'
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.android.support:support-annotations:25.1.1'
    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

    ... 
    testCompile 'org.robolectric:shadows-support-v4:3.2.2'
    testCompile 'org.robolectric:shadows-play-services:3.2.2'
    testCompile 'com.jakewharton:butterknife:8.5.1'
    testCompile 'com.android.support:support-annotations:25.1.1'
    testCompile 'com.google.dagger:dagger:2.8'
    testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.8'
   ...
}

Most helpful comment

A much better approach is using a resolution strategy to force the versions across all configurations:

configurations.all {
  resolutionStrategy {
    eachDependency { details ->
      // Force all of the primary support libraries to use the same version.
      if (details.requested.group == 'com.android.support') {
        details.useVersion versions.supportLibrary
      }
    }
  }
}

All 6 comments

Add testCompile 'com.android.support:support-compat:25.1.1'

Darn! Did the trick. Thanks.

A much better approach is using a resolution strategy to force the versions across all configurations:

configurations.all {
  resolutionStrategy {
    eachDependency { details ->
      // Force all of the primary support libraries to use the same version.
      if (details.requested.group == 'com.android.support') {
        details.useVersion versions.supportLibrary
      }
    }
  }
}

Seems like a more elegant solution indeed, yet doesn't work (can't resolve the dependencies anymore now). Must admit that these resolutionStrategies are still a bit of a blind spot for me.

I assure you it works. Did you replace versions.supportLibrary with a
reference to a string or variable with the version string?

On Thu, Feb 2, 2017, 2:50 AM Kris Vandermast notifications@github.com
wrote:

Seems like a more elegant solution indeed, yet doesn't work (can't resolve
the dependencies anymore now). Must admit that these resolutionStrategies
are still a bit of a blind spot for me.

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/JakeWharton/butterknife/issues/861#issuecomment-276890137,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEETtWblpgPfFb8DKzXwAW-497DZGYks5rYYrbgaJpZM4Lz3jS
.

Just had a quick look again, based upon your feedback.

  • It didn't like the details.useVersion ${ANDROID_SUPPORT_VERSION} which I put there in the first place, it should be surrounded by quotes
  • It should exclude the com.android.support:multidex dependencies, as they don't have the same version increment.
def ANDROID_SUPPORT_VERSION = "25.1.1"
...
configurations.all {
    resolutionStrategy.force 'com.google.guava:guava:20.0'

    resolutionStrategy {
        eachDependency { details ->
            if(details.requested.group == 'com.android.support')
            {
                // println "Checking ${details.requested.group}:${details.requested.name} "

                if(details.requested.name != 'multidex' && details.requested.name != 'multidex-instrumentation') {
                    details.useVersion "${ANDROID_SUPPORT_VERSION}"
                }
            }
        }
    }
}
Was this page helpful?
0 / 5 - 0 ratings