【问题标题】:how to solve the conflict in jar files dependencies in Android studio如何解决Android Studio中jar文件依赖关系的冲突
【发布时间】:2016-11-26 03:36:06
【问题描述】:

大家好,我有一个项目,我今天在导入 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

在某些类上存在冲突。这些是我的依赖项

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')
}

你能帮帮我吗

【问题讨论】:

  • 使用app:dependencies 查看依赖树。通常会指出堆栈跟踪中哪个类发生冲突。搜索那个并将其从您的依赖项之一中排除。
  • 如何从jar文件的依赖中排除一个类,以及如何查看这个应用:依赖
  • 我觉得可能是 facebook1.jar 或 gcm.jar 与您的播放服务冲突

标签: java android eclipse android-studio


【解决方案1】:

使用app:dependencies 查看依赖树。通常会指出堆栈跟踪中哪个类发生冲突。搜索那个并将其从您的依赖项之一中排除。

打开Gradle 窗口并单击execute Task(它是一个图标)。输入app:dependencies,您将在Messages 窗口中看到您的gradle 树。

搜索冲突的类并像这样排除它,例如:

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

【讨论】:

    【解决方案2】:

    您可以通过清单覆盖以下库来解决冲突:

    例如,在主要的 android 清单中:

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

    工具:覆盖库标记

    一种特殊标记,只能与 uses-sdk 声明一起使用 覆盖导入最低 SDK 版本更新的库 高于该应用程序的最低 SDK 版本。没有这样的标记, 清单合并将失败。标记将允许用户选择 可以导入哪些库而忽略最低 SDK 版本。

    Reference

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      • 2015-05-09
      • 2016-03-06
      • 2018-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多