Android 工作室 java.lang.NoClassDefFoundError: android.support.v4.app.NavUtilsJB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28298453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android studio java.lang.NoClassDefFoundError: android.support.v4.app.NavUtilsJB
提问by Alpha
This is my error log acheived with android studio 1.0.2
这是我使用 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.access0(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.
如何解决这个错误?gradlew clean 无济于事。构建文件夹删除也不起作用。Android studio 编译时没有显示错误。
回答by Sam
I had this problem and just found the solution - answer is RTFM! Here are the instructions: https://developer.android.com/tools/building/multidex.html
我遇到了这个问题,刚刚找到了解决方案 - 答案是 RTFM!以下是说明: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:
Multidexing 是一项新功能,因此需要一个支持库来与 pre-lollipop 设备兼容。您需要将以下内容添加到您的 gradle 文件依赖项中:
compile 'com.android.support:multidex:1.0.0'
Also enable multidex output in your gradle file:
还要在您的 gradle 文件中启用 multidex 输出:
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:
然后将 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>
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.
注意:如果您的应用程序已经扩展了 Application 类,您可以覆盖 attachBaseContext() 方法并调用 MultiDex.install(this) 来启用 multidex。有关更多信息,请参阅MultiDexApplication
参考文档。
@Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
MultiDex.install(this);
}
Again, see the instruction above for more information...
同样,请参阅上面的说明以获取更多信息...
Hope this helps
希望这可以帮助
回答by Ahsanwarsi
Was stuck for hours due to this issue but finally got the solution.
由于这个问题被困了几个小时,但最终得到了解决方案。
Step#1:
步骤1:
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Step#2:
第2步:
defaultConfig {
multiDexEnabled true
}
Step#3:
第 3 步:
public class AppController extends Application {
@Override
public void onCreate() {
super.onCreate();
MultiDex.install(this);
}
}
Happy coding!
快乐编码!
回答by Fred Sousa
Following solution worked for me:
以下解决方案对我有用:
Add
multiDexEnabled = true
in yourdefault Config
Add compile
com.android.support:multidex:1.0.0
in your dependenciesApplication class extend MultiDexApplication
instead of justApplication
加入
multiDexEnabled = true
你的default Config
com.android.support:multidex:1.0.0
在您的依赖项中添加编译Application class extend MultiDexApplication
而不仅仅是Application
回答by Maxim Mikhisor
In our case we got this error when we updated "support-v4" lib from 19 to 24 version.
在我们的例子中,当我们将“support-v4”库从 19 版本更新到 24 版本时,我们遇到了这个错误。
Version 19 contains NavUtilsJBclass:
版本 19 包含NavUtilsJB类:
But version 24 does not contain NavUtilsJBclass:
但是版本 24 不包含NavUtilsJB类:
Solution for this issue was just to create NavUtilsJBclass inside our project:
这个问题的解决方案只是在我们的项目中创建NavUtilsJB类:
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;
}
}