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

查看:87
本文介绍了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正常工作?换句话说,为什么配置部分只应排除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

  1. Removed the config section in the build.gradle that excludes 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天全站免登陆