I'm trying to add 'commons-validator' to my android project in Android Studio based on gradle. I use UrlValidator for my needs.
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
}
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.
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
and also I get
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 times: two for debug and two for release.
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.I think the problem were transitive dependencies. After researching some SO's threads I wrote in my console:
which gave me following output:
So I added this to build.gradle:
Also some people told to add
multiDexEnabled true
todefaultConfig
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: