Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This is my error log acheived with android studio 1.0.2

02-03 13:05:23.831    8385-8385/com.******.*******E/AndroidRuntime﹕     FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: android.support.v4.app.NavUtilsJB
        at   android.support.v4.app.NavUtils$NavUtilsImplJB.getParentActivityName(NavUtils    .java:125)
        at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:302)
        at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:281)
        at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:142)
        at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
        at com..******.*******.****.ActivityWelcome.onCreate(ActivityWelcome.java:33)
        at android.app.Activity.performCreate(Activity.java:5104)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
        at android.app.ActivityThread.access$600(ActivityThread.java:141)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5041)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        at dalvik.system.NativeStart.main(Native Method)

Configuration

buildToolsVersion "21.1.2"
android SDK TOOLS"24.0.2"
multidex enabled
predexLibraries =false
incremental = true
jumboMode = false
  dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:6.5.87'
    compile 'com.google.code.gson:gson:2.3'
    compile 'com.android.support:support-v4:21.0.3@aar'
    compile 'com.android.support:appcompat-v7:21.0.3@aar'
    compile project(':ViewPagerIndicator')
    compile('de.keyboardsurfer.android.widget:crouton:1.8.4@aar') {
        exclude group: 'com.google.android', module: 'support-v4'
    }
    compile 'org.java-websocket:Java-WebSocket:1.3.0'
}

How to solve this error? gradlew clean not helps. Build folders deletion also not working. Android studio shows no errors while compiling.

like image 620
Alpha Avatar asked Feb 03 '15 12:02

Alpha


2 Answers

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

like image 121
Sam Avatar answered Oct 26 '22 21:10

Sam


Was stuck for hours due to this issue but finally got the solution.

Step#1:

dependencies {
compile 'com.android.support:multidex:1.0.0'
}

Step#2:

defaultConfig {
        multiDexEnabled true
    }

Step#3:

public class AppController extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        MultiDex.install(this);
    }
}

Happy coding!

like image 36
Ahsanwarsi Avatar answered Oct 26 '22 22:10

Ahsanwarsi