Can't add dependency to Android Project

淺唱寂寞╮ 提交于 2019-12-08 20:01:31

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

which gave me following output:

_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

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'
}

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

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

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

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

Try removing the <uses-library> tag. That's for requiring the user to have a certain external library installed before they can install your app. The gradle dependency should be sufficient since you want to include the library internally within your code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!