Java.lang.NoClassDefFoundError on Android 4.4 or lower

I have an Android app that I recently upgraded to the Gradle build system, among other things, for example, using a new version of the build tools, etc.

My targetSdkVersion is 19, so it should be nice for me to go on Android 4.4 and higher. When I start using the 5.0+ device, everything is fine; however, Android 4.4 always crashes with the java.lang.NoClassDefFoundError error.

As a test, I removed the original class, which complained about the absence, only to make it work, pointing to another class.

The first class he crashed with was an internal private class in a third-party library. After removing this library, he pointed to an internal private class in the application itself.

In short:

  • The app works fine on Android 5.0+. It crashes with java.lang.NoClassDefFoundError on something less than 5.0.
  • In tests so far, NoClassDef always refers to an inner class - it is simply based on two tests, so there may not be anything specific.

Here is my android.manifest file: https://gist.github.com/rscott78/19dd88ccde66172d9332

+8
android studio
source share
1 answer

For what it's worth, it can happen if you enable multi-dex support without adding the correct code to your Application class.

Create a class, inherit it from the application, then add this override:

 @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } 

In your AndroidManifest, add the name attribute to the application tag:

 <application name=".MyApplication" 
+19
source share

All Articles