android中的gradle依赖错误 [英] gradle dependency error in android

查看:21
本文介绍了android中的gradle依赖错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In the following build.gradle, I added the configuration section to avoid double inclusion of support libraries. Support libraries are used in the main project and in the dependent projects like facebook sdk. Without the configuration section, I get "UNEXPECTED TOP-LEVEL EXCEPTION". Adding that configuration makes the error go away and the app all works fine.

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

Now, I'm trying to add RecyclerView to my app and I get RecyclerView class not found while inflating the recyclerview (although it builds ok). If I remove the facebook SDK and configuration section, the recyclerview works just fine.

问题:我可以对 build.gradle 进行哪些更改以使 facebook SDK 工作和 RecyclerView 工作?换句话说,为什么 config 部分只应该排除 v4 而排除 v7?

Question: What changes can I make to the build.gradle to make the facebook SDK work and RecyclerView work? In other words, why is the config section excluding v7 when it is only supposed to exclude 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'
}

推荐答案

找到了解决方案:

  1. 删除了 build.gradle 中排除 support-v4

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

It turns out that .aar files are basically a zip, so removed the support-v4 jar from the dependency .aar library (using 7-zip). And now, I don't get the top-level exception and at the same time able to use recyclerview-v7.

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

If you are using dependency projects instead of .aar files, try removing the support-v4.jar files in the dependency projects before compiling.

gradle 构建工具不应该足够智能以排除重复的包,而不是让用户经历这种变通方法和头痛吗?

Shouldn't the gradle build tool be intelligent enough to exclude the duplicate packages rather than having the users go thru this kind of workarounds and headaches?

这篇关于android中的gradle依赖错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆