How to add apache commons collections in Android S

2019-01-08 04:05发布

问题:

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?

回答1:

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



回答2:

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)

implements 'org.apache.commons:commons-collections4:4.1'

lang: (link)

implements 'org.apache.commons:commons-lang3:3.7'

compress: (link)

implements 'org.apache.commons:commons-compress:1.17'

net: (link)

implements 'commons-net:commons-net:3.6'

io: (link)

implements 'commons-io:commons-io:2.6'

exec (link)

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

codec (link)

implements 'commons-codec:commons-codec:1.11'

http (link)

implements 'org.apache.httpcomponents:httpclient:4.5.5'

validator (link)

implements 'commons-validator:commons-validator:1.6'

math (link)

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

See all of the Apache libraries here