简体   繁体   中英

how to solve the conflict in jar files dependencies in Android studio

hello guys i have a project that i migrated from eclipse to android studio today after importing the speedchecker library and as it shows the

speedchecker-android-sdk-1.2.jar
httpcore-4.3-beta1.jar
httpclient-4.3-beta1.jar
httpclient-cache-4.3-beta1.jar
httpmime-4.3-beta1.jar

are conflicting on some classes. these are my dependencies

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:multidex:1.0.1'
compile('com.octo.android.robospice:robospice-google-http-client:1.4.14') {
    exclude module: 'commons-io'
    exclude group: 'org.apache.commons'
}
compile('com.google.http-client:google-http-client-jackson2:1.19.0') {
    exclude module: 'commons-io'
    exclude module: 'xpp3'
    exclude group: 'stax'
}
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.code.gson:gson:2.6.2'
compile files('libs/activation.jar')

//conflict in here
compile files('libs/speedchecker-android-sdk-1.2.jar')
compile files('libs/httpcore-4.3-beta1.jar')
compile files('libs/httpclient-4.3-beta1.jar')
compile files('libs/httpclient-cache-4.3-beta1.jar')
compile files('libs/httpmime-4.3-beta1.jar')

compile files('libs/additionnal.jar')
compile files('libs/facebook1.jar')
compile files('libs/mail.jar')
compile files('libs/universal-image-loader-1.9.5.jar')
compile files('libs/gcm.jar')
}

can you please help me

Use app:dependencies to see the dependency tree. Normally it is pointed out which class is conflicting in the stacktrace. Search for that one and exclude it from one of your dependencies.

Open the Gradle window and click on execute Task (it's a icon). Type in app:dependencies and you will see your gradle tree in the Messages window.

Search the conflicting class and exclude it like this for eg:

 compile('commons-validator:commons-validator:1.5.0') {
        exclude group: 'commons-logging', module: 'commons-logging'
    }

You can resolve the conflicts by overriding libraries as follows via your manifest:

Example, In the main android manifest :

<uses-sdk android:targetSdkVersion="14" android:minSdkVersion="2"
              tools:overrideLibrary="com.example.lib1, com.example.lib2"/>

tools:overrideLibrary marker

A special marker that can only be used with uses-sdk declaration to override importing a library which minimum SDK version is more recent than that application's minimum SDK version. Without such a marker, the manifest merger will fail. The marker will allow users to select which libraries can be imported ignoring the minimum SDK version.

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM