问题描述
添加新模块时出现奇怪的错误 (https://github.com/lomza/android-color-picker) 到我的项目.没有这个模块项目运行良好,但如果将此项目作为模块添加到我的主项目并编译它 - 一切看起来都不错,但应用程序启动并立即强制关闭给我这个错误:
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 行是 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?
我发现该项目在 API 21 上运行良好,但如果我在 API 18 上运行它,则会出现错误.
I find out that project runs fine on API 21, but if I run it on API 18, I am getting error.
推荐答案
我找到了这个问题的解决方案.我使用的是多索引,它仅在 Lolipop 设备中可用,因此,要在 Lolipop 之前的设备中使用它,我需要添加此行
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
编译'com.android.support:multidex:1.0.0'
到 build.gradle
文件
还有这一行android:name="android.support.multidex.MultiDexApplication"
到 标签中的
AndroidManifest.xml
.
and this one line
android:name="android.support.multidex.MultiDexApplication"
to AndroidManifest.xml
in <appplication
tag.
对我来说 - 现在一切正常.
For me - now everything works fine.
,而不是在清单中向
android:name
添加行,您可以将 multiDexEnabled = true
添加到 gradle
defaultConfig
中的 code> 文件.
instead of adding line to
android:name
in manifest, you can add multiDexEnabled = true
to gradle
file in defaultConfig
.
这篇关于java.lang.NoClassDefFoundError: android.support.v4.app.NavUtilsJB 在 Android Studio 中添加新模块时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!