1

I have an Android project that requires the Jsoup library. I've tried everything I can think of to get the jar shaded into the APK.. I just can't get it working. Logcat tells me:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: org.jsoup.Jsoup

Does anyone know how to include/shade a maven artifact into an APK with Android Studio?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Mike724
  • 23
  • 4

2 Answers2

1

I have found the answer. The trick is to append ":sources". See an example here: http://www.alonsoruibal.com/my-gradle-tips-and-tricks/

Mike724
  • 23
  • 4
  • Also, in settings.gradle I added jsoup, so it looks similar to this: include ':PSMonitor', 'org.jsoup:jsoup' – Mike724 Sep 28 '13 at 18:28
  • 1
    I seem to have the [same Gradle problem with the Jackson library](http://stackoverflow.com/questions/19245855/noclassdeffounderror-using-jackson-2-2-x-on-android-with-gradle). I would be happy if you can take a look at my question. I appended `:sources` in `build.gradle` and `'com.fasterxml.jackson.core'` in `settings.gradle` - same error message though. – JJD Oct 09 '13 at 14:12
0

I have seen the same type of error every time someone else adds a library with Gradle. Build is usually successful but app crashes when it tries to use the new library. Running task clean with Gradle helps.

Kuitsi
  • 1,675
  • 2
  • 28
  • 48