Shahek
Shahek

Reputation: 83

Android app and library dependencies clash

my app uses these dependencies

 compile 'com.android.support:appcompat-v7:22.2.1'
 compile 'com.android.support:design:22.2.1'
 compile 'com.google.android.gms:play-services:7.0.0'
 compile 'com.google.code.gson:gson:2.2.4'

when i imported seek arc library it uses different dependencies

  compile 'com.android.support:appcompat-v7:23.4.0'
  compile 'com.android.support:appcompat-v7:23.2.1'
  compile 'com.android.support:design:23.2.1'
  compile project(':SeekArc_library')

How can i solve this problem ?

Upvotes: 2

Views: 785

Answers (4)

Akki
Akki

Reputation: 96

If you want to exclude the dependancies of the library you are using you can

compile 'yourLibraryName'{
   exclude module: 'appcompat-v7' 
   exclude module: 'appcompat-v7' 
 }

Make sure you provide your own version though, otherwise you'll get runtime errors

Upvotes: 0

Shahek
Shahek

Reputation: 83

My App and newly added Library dependencies were in conflict. I changed app compiled & build sdk to api 23 and added "useLibrary 'org.apache.http.legacy'". Now problem solved.

Upvotes: 1

Creos
Creos

Reputation: 2535

I am assuming you are using the standard gradle build tooling and Android Studio.

Below is the recommended solution for issues of clashing dependencies. Eg say you have declared an explicit dependency on com.google.guava version X but some other dependency is bringing its own internal dependency on com.google.guava version X-1.

Add the following after your dependencies clause in the build.gradle file.

configurations {
    all*.exclude group: 'com.google.guava', module: 'guava-jdk5'
}

For details see https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.Configuration.html

Note: there is another approach where you may selectively exclude certain dependency from each compile clause but it is not recommended since it doesn't scale well. For completeness I'll include it here but I do not recommend it. Using the same made-up example as above

compile(group: 'com.google.guava', name: 'guava', version: 'X')
compile(group: 'com.some.other.dependency', name: 'foo', version: 'bar')
{
    // exclude transitive dependency since we want to depend on version `X` declared above
    exclude(group: 'com.google.guava', module: 'guava-jdk5')
}    

Upvotes: 2

Nandish A
Nandish A

Reputation: 1705

The top level applications library dependency will override the lower level library dependency . You don't need to override explicitly. Refer to Android build documentation

Upvotes: 0

Related Questions