65

Due to this question I want to use class StringEscapeUntils in package org.apache.commons.lang3.

But when I try to import Apache lib by add line compile 'org.apache.commons:commons-collections4:4.0' to build.grade file then can not import the class above.

Is there any one can help me how to import above one to my project via gradle (not by download .jar and put them into project folder).

Community
  • 1
  • 1
ThaiPD
  • 3,503
  • 3
  • 30
  • 48

4 Answers4

191

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!

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
AndiGeeky
  • 11,266
  • 6
  • 50
  • 66
8

for StringUtils you need to add in app.gradle

implementation 'org.apache.commons:commons-text:1.7'
Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
f.asuma
  • 81
  • 1
  • 4
7

StringEscapeUtils class moved to org.apache.commons:commons-text. package.

For StringEscapeUtils you need to add 'org.apache.commons:commons-text:1.6' dependency.

Smarpit
  • 99
  • 1
  • 13
0

After adding

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

in build.gradle as mentioned above, some of you might be facing the following exception on rebuild:

Invoke-customs are only supported starting with android 0 --min-api 26

In this case, just add the follwing in your build.gradle as well:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

NOTE:

The example above is for Java 8. For those who are on Java 7, simply replace 1_8 by 1_7.

mang4521
  • 742
  • 6
  • 22