How to Add Apache Commons Collections in Android Studio (Gradle)

How to add apache commons collections in Android Studio (Gradle)

Place the jar file in the libs folder in the root of your module. Then File -> Project Settings. In the left side choose the module where you want to add this lib, in the right side choose tab Dependencies. In the bottom press Plus sign and click File dependency. Then choose your jar and sync project

How to add org.apache.commons.lang3 to AndroidStudio with gradle

Edited 07.12.2018:

I think dependency for StringUtils you are using is not proper.

Please add below dependency to gradle and Sync project and import your class.

implementation 'org.apache.commons:commons-lang3:3.6'

This on is using deprecated task (but should still works):

compile 'org.apache.commons:commons-lang3:3.5'

Edit:

As OoDeLally mentioned in a comment,

Above mentioned version is deprecated,
Please use below dependency:

implementation 'org.apache.commons:commons-text:1.9'

Edit 2:

deprecated as for July 2019. Use stackoverflow.com/a/55567755/1541141 instead

Thanks @OoDeLally!

org.apache.commons in Android Studio build.gradle file

problem is that you are missing this at the top level :You also need repositories and dependencies at the top level for the dependencies for your project itself.For more information you can see these solutions commas error and also here .

apply plugin: 'android'

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
}
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 116
}
}

repositories{
mavenCentral()
}

dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}

May it helps and solve problem.

In Android Studio how do you find which dependency to add?

try this for maven :

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>

or this for gradle:

implementation 'org.apache.commons:commons-collections4:4.4'

Gradle can't find Apache commons

That's because the correct group is commons-io

compile group: 'commons-io', name: 'commons-io', version: '2.4'

Reimport, and it will be picked up.

Can't add dependency to Android Project

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



Related Topics



Leave a reply



Submit