java.lang.NoClassDefFoundError: android.support.v4.app.NavUtilsJB error when adding new module in Android Studio

拈花ヽ惹草 提交于 2019-12-01 07:55:29

问题


I have a strange error adding new module (https://github.com/lomza/android-color-picker) to my project. Without this module project runs fine, but if add this project as module to my main project and compile it - everything looks good, but app starts and force closes instantly giving me this error:

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 app.user.views.ActivityWelcome.onCreate(ActivityWelcome.java:33)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

ActivityWelcome.java 33 line is super.onCreate(savedInstanceState);

If I remove this module from project - everything runs fine again. I have same problem adding any new module to my project. Where is the problem?

EDIT: I find out that project runs fine on API 21, but if I run it on API 18, I am getting error.


回答1:


I found solution for this problem. I was using multidexing and it is available only in Lolipop devices, so, to use it in pre-Lolipop devices I needed to add this line

compile 'com.android.support:multidex:1.0.0' to build.gradle file

and this one line android:name="android.support.multidex.MultiDexApplication" to AndroidManifest.xml in <appplication tag.

For me - now everything works fine.

EDIT: instead of adding line to android:name in manifest, you can add multiDexEnabled = true to gradle file in defaultConfig.




回答2:


Based on the stack trace, I would strongly suspect a problem with support library version mismatches. For example, it appears that the android-color-picker library relies on a quite outdated version of the support library (updated over a year ago). Perhaps your main project is using a more recent version of the support library? In order to avoid this crash, I would recommend reconfiguring the android-color-picker library to use the same version of the support library that you are using elsewhere in your project.



来源:https://stackoverflow.com/questions/28562172/java-lang-noclassdeffounderror-android-support-v4-app-navutilsjb-error-when-add

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!