与超过64K的方法来配置应用程序
07-19 18:20:29.491 11778-11778/com.example.hante.newpro E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.hante.newpro, PID: 11778
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.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:152)
at android.support.v7.app.AppCompatDelegateImplV14.onCreate(AppCompatDelegateImplV14.java:46)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:73)
at com.example.hante.newpro.MainActivity2.onCreate(MainActivity2.java:150)
at android.app.Activity.performCreate(Activity.java:5245)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2238)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5016)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
解决步骤:
1.You need to add the following to your gradle file dependencies:
compile 'com.android.support:multidex:1.0.0'
2.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
}
}
3.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>
重新编译就ok
参考:Android 文档 https://developer.android.com/studio/build/multidex.html
及
http://stackoverflow.com/questions/28298453/android-studio-java-lang-noclassdeffounderror-android-support-v4-app-navutilsjb