简体   繁体   English

如何解决Android Studio中jar文件依赖项中的冲突

[英]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库后,我今天从eclipse迁移到了android studio,它显示了

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. 使用app:dependencies查看依赖关系树。 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). 打开Gradle窗口,然后单击execute Task (它是一个图标)。 Type in app:dependencies and you will see your gradle tree in the Messages window. 输入app:dependencies ,您将在“ Messages窗口中看到您的gradle树。

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 : 例如,在主要的Android清单中:

<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. 一个特殊标记,只能与uses-sdk声明一起使用,以覆盖导入其最低SDK版本比该应用程序的最低SDK版本新的库。 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. 该标记将允许用户选择要导入的库,而无需考虑最低的SDK版本。

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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