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

后端 未结 4 1850
执念已碎
执念已碎 2020-12-15 09:40

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
    ja         


        
相关标签:
4条回答
  • 2020-12-15 09:55

    In our case we got this error when we updated "support-v4" lib from 19 to 24 version.

    Version 19 contains NavUtilsJB class:

    But version 24 does not contain NavUtilsJB class:

    Solution for this issue was just to create NavUtilsJB class inside our project:

    package android.support.v4.app;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.content.pm.ActivityInfo;
    
    class NavUtilsJB {
        public static Intent getParentActivityIntent(Activity activity) {
            return activity.getParentActivityIntent();
        }
        public static boolean shouldUpRecreateTask(Activity activity, Intent targetIntent) {
            return activity.shouldUpRecreateTask(targetIntent);
        }
        public static void navigateUpTo(Activity activity, Intent upIntent) {
            activity.navigateUpTo(upIntent);
        }
        public static String getParentActivityName(ActivityInfo info) {
            return info.parentActivityName;
        }
    }
    
    0 讨论(0)
  • 2020-12-15 10:05

    Following solution worked for me:

    1. Add multiDexEnabled = true in your default Config

    2. Add compile com.android.support:multidex:1.0.0 in your dependencies

    3. Application class extend MultiDexApplication instead of just Application

    0 讨论(0)
  • 2020-12-15 10:14

    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

    0 讨论(0)
  • 2020-12-15 10:18

    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!

    0 讨论(0)
提交回复
热议问题