android中的gradle依赖错误

nom*_*ngo 12 android android-gradle-plugin android-recyclerview

在下面的build.gradle中,我添加了配置部分以避免双重包含支持库.支持库用于主项目和依赖项目,如facebook sdk.如果没有配置部分,我会得到"意想不到的顶级异常".添加该配置会使错误消失,应用程序一切正常.

现在,我正在尝试将RecyclerView添加到我的应用程序中,并且在充气Recyclerview时找不到RecyclerView类(尽管它构建正常).如果我删除了facebook SDK和配置部分,则recyclerview工作正常.

问题:我可以对build.gradle进行哪些更改以使facebook SDK正常工作并且RecyclerView可以正常工作?换句话说,为什么配置部分不包括v7,只是它应该排除v4?


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v4:+'
    compile 'com.android.support:support-v13:+'
    compile 'com.android.support:cardview-v7:+'
    compile 'com.android.support:recyclerview-v7:+'
    compile 'com.google.android.gms:play-services:4.4.52'
    compile project(':facebook-3.15')
    compile project(':parse-1.5.1')
    compile project(':viewpagerindicator-2.4.1')
}

configurations {
    // to avoid double inclusion of support libraries
    all*.exclude group: 'com.android.support', module: 'support-v4'
}
Run Code Online (Sandbox Code Playgroud)

kco*_*ock 13

如果您与v4支持库存在依赖冲突,则可以通过gradle脚本将其从其中一个库中排除:

compile ('com.android.support:recyclerview-v7:+') {
    exclude module: 'support-v4'
}
Run Code Online (Sandbox Code Playgroud)


nom*_*ngo 4

找到了解决这个问题的方法:

  1. 删除了build.gradle中排除的配置部分support-v4

  2. 事实证明,.aar文件基本上是一个 zip,因此从依赖项 .aar 库中删除了 support-v4 jar(使用 7-zip)。现在,我没有得到顶级异常,同时能够使用recyclerview-v7.

如果您使用依赖项目而不是 .aar 文件,请尝试在编译之前删除依赖项目中的 support-v4.jar 文件。

难道 gradle 构建工具不应该足够智能来排除重复的包,而不是让用户经历这种解决方法和令人头痛的事情吗?