Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android Gradle构建中,如何从包含的jar文件中排除依赖项?_Android_Gradle_Jar_Android Gradle Plugin - Fatal编程技术网

在Android Gradle构建中,如何从包含的jar文件中排除依赖项?

在Android Gradle构建中,如何从包含的jar文件中排除依赖项?,android,gradle,jar,android-gradle-plugin,Android,Gradle,Jar,Android Gradle Plugin,在我的Android项目中,我使用一个作为jar的库。 我将其包含在依赖项部分,如下所示: dependencies { ... compile files('libs/thethirdpartylibrary.jar') ... } 我还想使用okhttp库,其中包括: compile ('com.squareup.okhttp:okhttp:2.7.5') (此特定版本的okhttp取决于okio 1.6.0。) 问题在于,第三方jar库依赖于okio v0.9

在我的Android项目中,我使用一个作为jar的库。 我将其包含在依赖项部分,如下所示:

dependencies {
    ...

    compile files('libs/thethirdpartylibrary.jar')
    ...
}
我还想使用okhttp库,其中包括:

compile ('com.squareup.okhttp:okhttp:2.7.5')
(此特定版本的okhttp取决于okio 1.6.0。)

问题在于,第三方jar库依赖于okio v0.9.0,更糟糕的是,将其捆绑

结果,我在构建时得到了一个dex冲突错误

我可以通过手动从jar文件中删除okio来解决这个问题,这似乎是可行的。但我想知道在格拉德尔是否有办法做到这一点


我的问题:我可以使用下面的行删除捆绑的、可传递的(排除依赖项中的组吗

一,

二,

三,

试试这个


根据这里的讨论,您想做的是不可能的


其他答案中建议的语法适用于“普通”Maven依赖项。

2.此语法不适用于基于文件的jar文件(AFAIK…)3.我不想这样做,因为我真的想包括一个版本的库--我只是不想使用JAR中的版本。有三个选项可以排除依赖项,但它并没有真正回答核心问题,即:如何从JAR中排除依赖项。但它似乎可以从所有内容中删除依赖项,所以不幸的是,这对我没有帮助;-|谢谢你的努力,顺便说一句!你为什么不能简单地重新创建第三方jar来删除其中你不想要的类呢?我不认为gradle会允许你从文件依赖中选择要排除的特定类。事实上,这就是我现在正在做的。我只是想知道是否有(简单)使用gradle执行此操作的方法,这样我就不必每次供应商库更改时都手动执行此操作。您好,您解决了此问题吗?您能分享您的解决方案吗?
configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}
dependencies {
    compile 'com.android.support:support-v4:13.0.+'
    compile ("com.xxx:xxx-commons:1.+") {
        exclude group: 'junit', module: 'junit'
    }
}
configurations {
    runtime.exclude group: "org.slf4j", module: "slf4j-log4j12"
}