Noclassdeffounderror with Android Studio on Android 4

NoClassDefFoundError with Android Studio on Android 4

I was incompletely implementing MultiDex support, so some of my classes weren't in the proper dex file. To fix it, you have to do more than just set multiDexEnabled = true in your defaultConfig block. You also have to:

  1. Include compile 'com.android.support:multidex:1.0.1' in your dependencies
  2. Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application.

See https://developer.android.com/tools/building/multidex.html for more details.

Android NoClassDefFoundError on android 4.4.2

You can find the answer for this question here:

  1. NoClassDefFoundError with Android Studio on Android 4
  2. https://developer.android.com/studio/build/multidex

Android studio java.lang.NoClassDefFoundError: android.support.v4.app.NavUtilsJB

I had this problem and just found the solution - answer is RTFM! Here are the instructions: https://developer.android.com/tools/building/multidex.html

Multidexing is a new feature and so requires a support library to be compatible with pre-lollipop devices. You need to add the following to your gradle file dependencies:

compile 'com.android.support:multidex:1.0.0'

Also enable multidex output in your gradle file:

android {
compileSdkVersion 21
buildToolsVersion "21.1.0"

defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...

// Enabling multidex support.
multiDexEnabled true
}
}

And then add the multidex support application to your manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>

Note: If your app already extends the Application class, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex. For more information, see the MultiDexApplication reference documentation.

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

Again, see the instruction above for more information...

Hope this helps

android studio java.lang.NoClassDefFoundError Gson

Had the same issue. What I did was gradle clean and then build my project with gradle from console. In my build.gradle gson dependency looks like this:

dependencies {
compile 'com.google.code.gson:gson:2.2.4'
}

NoClassDefFoundError on Android Studio project that builds fine

ok, it seems that the error was due to a very different reason:

The app was updated to use Google Services 7.5 which made the methods go to more than 65k which made me to add the mutiDexEnabled to true.

I don't know if the code needs to be changed to support that, but it seems that after making this change, the app was crashing at random points (when I remarked the history call, the reachability class was crashing, when removed the reachability another, etc.

of course all classes were at the right place when the compiler complained about not finding them
This made me wonder if the multidex caused that so I removed some of the libraries like going from 7.5 verson of google play to 6.5

The app compiles and runs just fine now, allowing me to add the FB sdk 4+

I post this here, so it may help other people having problems without being able to understand where they come from.



Related Topics



Leave a reply



Submit