无法将依赖项添加到Android Project [英] Can't add dependency to Android Project

查看:107
本文介绍了无法将依赖项添加到Android Project的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于gradle将'commons-validator'添加到我在Android Studio中的android项目中.我根据需要使用UrlValidator.

I'm trying to add 'commons-validator' to my android project in Android Studio based on gradle. I use UrlValidator for my needs.

因此,我在应用程序模块的build.gradle中添加了一个依赖项:

So I add a dependency in build.gradle of an app module:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'commons-validator:commons-validator:1.4.1' // this one
}

然后在应用程序标签中将using-library应用于AndroidManifest:

And uses-library to the AndroidManifest in application tag:

 <uses-library android:name="org.apache.commons.validator.routines.UrlValidator"
        android:required="true"/>

但是添加后,我的项目无法运行.

But after adding it my project fails to Run.

错误:任务':app:dexDebug'执行失败. com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:处理'command'/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java''完成退出值为2的非零值

Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

我也得到

警告:依赖项commons-logging:commons-logging:1.2在调试时会被忽略,因为它可能与Android提供的内部版本冲突. 如有问题,请用jarjar重新包装以更改类包

Warning:Dependency commons-logging:commons-logging:1.2 is ignored for debug as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages

4次:两次用于调试,两次用于发布.

4 times: two for debug and two for release.

推荐答案

我认为问题是传递依赖.研究了SO的一些线程之后,我在控制台中写了:

I think the problem were transitive dependencies. After researching some SO's threads I wrote in my console:

cd app/ #to enter app module folder
../gradlew dependencies

这给了我以下输出:

_debugCompile - ## Internal use, do not manually configure ##
+--- commons-validator:commons-validator:1.4.1
|    +--- commons-beanutils:commons-beanutils:1.8.3
|    |    \--- commons-logging:commons-logging:1.1.1 -> 1.2
|    +--- commons-digester:commons-digester:1.8.1
|    +--- commons-logging:commons-logging:1.2
|    \--- commons-collections:commons-collections:3.2.1

因此我将其添加到build.gradle:

So I added this to build.gradle:

compile('commons-validator:commons-validator:1.4.1'){
        exclude group: 'commons-logging'
        exclude group: 'commons-collections'
        exclude group: 'commons-digester'
        exclude group: 'commons-beanutils'
}

也有人告诉将multiDexEnabled true添加到defaultConfig部分,但是在我尝试不使用它的情况下,该功能对我来说是有效的.

Also some people told to add multiDexEnabled true to defaultConfig part but as I tried it works without it for me.

正如@Brucelet所说-从清单中删除了<uses-library>标签.

As @Brucelet said - removed <uses-library> tag from the manifest.

尽管gradle输出给出了许多AGPBI消息,但它可以正常运行并正常工作:

It runs and works correctly, although gradle output gives a lot of some AGPBI messages:

AGPBI:{种类":简单",文本":警告:忽略匿名内部类的InnerClasses属性",来源":[{}]} AGPBI:{"kind":"simple","text":(org.apache.commons.validator.CreditCardValidator $ 1)并不附带","sources:[{}]} AGPBI:{"kind":"simple","text":关联的EnclosingMethod属性.此类可能是由","sources":[{}]}产生的 AGPBI:{"kind":"simple","text":未针对现代.class文件格式的编译器.推荐的","sources":[{}]} AGPBI:{"kind":"simple","text":解决方案是使用最新的编译器从源代码重新编译类","sources":[{}]} AGPBI:{"kind":"simple","text":并且未指定任何\"-target \类型选项.忽略","sources":[{}]}的结果 AGPBI:{"kind":"simple","text":此警告是对此类的反射操作将不正确","sources":[{}]} AGPBI:{"kind":"simple","text":表明它不是内部类.","sources":[{}]} AGPBI:{"kind":"simple","text":警告:忽略匿名内部类的InnerClasses属性","sources":[{}]} AGPBI:{"kind":"simple","text":(org.apache.commons.validator.ValidatorResources $ 1)并不附带","sources:[{}]} AGPBI:{"kind":"simple","text":关联的EnclosingMethod属性.此类可能是由","sources":[{}]}产生的 AGPBI:{"kind":"simple","text":未针对现代.class文件格式的编译器.推荐的","sources":[{}]} AGPBI:{"kind":"simple","text":解决方案是使用最新的编译器从源代码重新编译类","sources":[{}]} AGPBI:{"kind":"simple","text":并且未指定任何\"-target \类型选项.忽略","sources"的结果:[{}]} AGPBI:{"kind":"simple","text":此警告是对此类的反射操作将不正确","sources":[{}]} AGPBI:{"kind":"simple","text":表明它不是内部类.","sources":[{}]}

AGPBI: {"kind":"simple","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]} AGPBI: {"kind":"simple","text":"(org.apache.commons.validator.CreditCardValidator$1) that doesn\u0027t come with an","sources":[{}]} AGPBI: {"kind":"simple","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]} AGPBI: {"kind":"simple","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]} AGPBI: {"kind":"simple","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]} AGPBI: {"kind":"simple","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]} AGPBI: {"kind":"simple","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]} AGPBI: {"kind":"simple","text":"indicate that it is not an inner class.","sources":[{}]} AGPBI: {"kind":"simple","text":"warning: Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]} AGPBI: {"kind":"simple","text":"(org.apache.commons.validator.ValidatorResources$1) that doesn\u0027t come with an","sources":[{}]} AGPBI: {"kind":"simple","text":"associated EnclosingMethod attribute. This class was probably produced by a","sources":[{}]} AGPBI: {"kind":"simple","text":"compiler that did not target the modern .class file format. The recommended","sources":[{}]} AGPBI: {"kind":"simple","text":"solution is to recompile the class from source, using an up-to-date compiler","sources":[{}]} AGPBI: {"kind":"simple","text":"and without specifying any \"-target\" type options. The consequence of ignoring","sources":[{}]} AGPBI: {"kind":"simple","text":"this warning is that reflective operations on this class will incorrectly","sources":[{}]} AGPBI: {"kind":"simple","text":"indicate that it is not an inner class.","sources":[{}]}

这篇关于无法将依赖项添加到Android Project的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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