Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

gradle

Im trying to use ListUtils but when I ran the app I got this error:

 Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.commons.collections.ListUtils" on path: DexPathList[[zip file "/data/app/com.meridianaspect.wiw-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] 

So I guess I have to import that library via gradle somehow, but I dont know how to do that?

like image 534
Kaloyan Roussev Avatar asked May 15 '15 12:05

Kaloyan Roussev


People also ask

What is Apache Commons Collections library?

The Apache Commons Collections are the components of the Apache Commons which are derived from Java API and provides component architecture for the Java language. Commons-Collections seek to build upon the JDK classes by providing new interfaces, implementations and utilities.

Where is the Gradle folder in Android studio?

gradle folder location for Android studio, you must: Define the GRADLE_USER_HOME environment variable to point to C:\WorkFolder\ . gradle. You can read more in the Configure the IDE docs.

Does Android studio include Gradle?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.


2 Answers

Pick the ones you need and add them to build.gradle's dependencies block:

I recommend checking the link to make sure you are getting the latest version. Feel free to suggest edits.

collections: (link)

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

lang: (link)

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

compress: (link)

implementation 'org.apache.commons:commons-compress:1.19' 

net: (link)

implementation 'commons-net:commons-net:3.6' 

io: (link)

implementation 'commons-io:commons-io:2.6' 

exec (link)

implementation 'org.apache.commons:commons-exec:1.3' 

codec (link)

implementation 'commons-codec:commons-codec:1.13' 

http (link)

implementation 'org.apache.httpcomponents:httpclient:4.5.10' 

validator (link)

implementation 'commons-validator:commons-validator:1.6' 

math (link)

implementation 'org.apache.commons:commons-math3:3.6.1' 

See all of the Apache libraries here

like image 93
Chad Bingham Avatar answered Oct 08 '22 08:10

Chad Bingham


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

like image 43
Oleg Osipenko Avatar answered Oct 08 '22 09:10

Oleg Osipenko