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


问题内容

这是我的错误日志与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)

组态

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'
}

如何解决这个错误?gradlew清洁无济于事。构建文件夹删除也不起作用。Android Studio编译时未显示任何错误。


问题答案:

我遇到了这个问题,只是找到了解决方法-
答案是RTFM!以下是说明:https
:
//developer.android.com/tools/building/multidex.html


Multidexing是一项新功能,因此需要支持库才能与棒棒糖之前的设备兼容。您需要将以下内容添加到gradle文件依赖项中:

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

同时在gradle文件中启用multidex输出:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

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

        // Enabling multidex support.
        multiDexEnabled true
    }
}

然后将multidex支持应用程序添加到清单中:

<?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>

注意:
如果您的应用程序已经扩展了Application类,则可以重写attachBaseContext()方法并调用MultiDex.install(this)以启用multidex。有关更多信息,请参见MultiDexApplication参考文档。

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

同样,请参阅上面的说明以获取更多信息…

希望这可以帮助