Android重复依赖项

时间:2015-09-01 16:18:49

标签: android gradle dependencies

我试图将unmano向上滑动面板库添加到我的android项目中,当我尝试运行该项目时出现此错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException: 
Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' 
finished with non-zero exit value 2

这是我的依赖列表:

dependencies {
    repositories {
        mavenCentral()
    }
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.google.android.gms:play-services-analytics:7.5.0'
    compile 'com.baoyz.pullrefreshlayout:library:1.0.1'
    compile fileTree(dir: 'libs', include: 'gson-*.jar')
    compile 'com.parse.bolts:bolts-android:1.2.1'
    compile fileTree(dir: 'libs', include: 'Parse-*.jar')
    compile 'com.fasterxml.jackson.core:jackson-core:2.4.2'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.4.2'
    compile 'com.sothree.slidinguppanel:library:3.1.1'
}

根据我在其他帖子上阅读的理解,有一个重复的文件导致此构建错误。有人可以帮助我理解我需要做些什么来解决这个问题吗?如何找到重复的文件?是否有任何gradle命令可用于检测和删除重复项?感谢

编辑:这是我的lib文件夹内容:

bolts-android-1.2.1.jar
gson-2.3.1.jar
Parse-1.10.0.jar
YoutubeAndroidPlayerApi.jar

3 个答案:

答案 0 :(得分:3)

似乎你已经包含了两次相同的库文件

compile fileTree(dir: 'libs', include: ['*.jar'])

compile fileTree(dir: 'libs', include: 'gson-*.jar')

compile fileTree(dir: 'libs', include: 'Parse-*.jar')

所以似乎gson-*.jarParse-*.jar包含两次。

修改

正如你所说的问题是umano向上滑动库,那么它应该是它的依赖性问题。

dependencies {
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:support-annotations:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.nineoldandroids:library:2.4.0'
}

我检查com.baoyz.pullrefreshlayout:library,它具有以下依赖性

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:21.0.0'
}

因此您包含了2个版本的支持库,因此遇到了问题。

compile 'com.baoyz.pullrefreshlayout:library:1.0.1'

要解决此问题,请将上面的行替换为下面的行。

compile('com.baoyz.pullrefreshlayout:library:1.0.1') { 
{
    exclude group: 'com.android.support', module: 'support-v4'
}

除上述内容外,请按照以下指南设置multidex

https://developer.android.com/tools/building/multidex.html

答案 1 :(得分:1)

你的第一个依赖

compile fileTree(dir: 'libs', include: ['*.jar'])

和这些

compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile fileTree(dir: 'libs', include: 'gson-*.jar')

编译相同的库。首先编译libs文件夹中的所有jar文件,其中存储了gson和Parse。 另外两个又添加了gson和Parse库。

如此简单地删除它们并添加类似的内容。

compile fileTree(dir: 'libs', include: ['*.jar'])    
......
compile files('libs/gson-*.jar')
compile files('libs/Parse-*.jar')

希望这有帮助。

答案 2 :(得分:1)

multiDexEnabled中的build.grade文件中将defaultConfig设为true。