Search code examples
gradledependenciesbuild.gradletransitive-dependency

Don't use later library version from transitive dependency in Gradle


in my Android project I use

compile 'com.squareup.okhttp:okhttp:2.2.0'

I need okhttp in version 2.2.0 for my code to work properly. But I have a problem when I add

compile('io.intercom.android:intercom-sdk:1.1.2@aar') {
        transitive = true
}

Because inside intercom-sdk there is okhttp dependency again for later version:

compile 'com.squareup.okhttp:okhttp:2.4.0'

Which results that my code uses that later version 2.4.0 instead of 2.2.0 I want. Is there please any way how in my module I can use 2.2.0 which I specified and let intercom to use its 2.4.0?


Solution

  • You can use something like this:

    compile('io.intercom.android:intercom-sdk:1.1.2@aar') {
        exclude group: 'com.squareup.okhttp', module: 'okhttp'
      }
    

    However pay attention. If the library uses methods that are not present in the 2.2.0 release, it will fail.