2015-11-20 86 views
1

我想添加'commons-validator'到基于gradle的Android Studio中的我的android项目。我使用UrlValidator来满足我的需求。不能添加依赖项到Android项目

所以我在添加一个应用程序模块的build.gradle的依赖关系:

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 
} 

而且使用图书馆的AndroidManifest应用标签:

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

但加入之后我的项目失败跑步。

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

而且我得到

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次:两个用于调试和两个用于释放。

回答

2

我认为问题是传递依赖。研究一些所谓的主题后,我在我的控制台中写道:

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:

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 truedefaultConfig部分,但因为我试过它没有它的作品对我来说。

As @Brucelet说 - 从清单中删除<uses-library>标记。

它运行和正常工作,虽然gradle这个输出给很多一些AGPBI消息:

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":[{}]}

0

尝试删除<uses-library>标记。这是为了要求用户在安装应用程序之前安装某个外部库。由于您希望在代码中内部包含库,因此Gradle依赖性应该足够。

相关问题