NoClassDefFoundError:Android 4.2.2上的android.support.design.internal.NavigationMenu(Wiko) [英] NoClassDefFoundError: android.support.design.internal.NavigationMenu on Android 4.2.2 (wiko)
问题描述
我正在尝试使用Android支持设计库(版本23.0.1)和类 NavigationMenu
(我将此类用作布局中的XML标签)
I am trying to use the Android Support Design library (in version 23.0.1) and the class NavigationMenu
(I use this class as an XML tag into a layout).
当我在Android 4.3上的Samsung或Android 5.x或6.0上的Nexus上执行我的应用程序时,一切正常,但是当我在Wiko Rainbow在Android 4.2.2上崩溃,但发生以下异常:
When I execute my app on a Samsung on Android 4.3 or on a Nexus on Android 5.x or 6.0 everything works well, but when I execute the app on a Wiko Rainbow on Android 4.2.2, it crashes with the following exception :
java.lang.RuntimeException: Unable to start activity ComponentInfo{applicationId/package.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
[...]
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
[...]
Caused by: java.lang.NoClassDefFoundError: android.support.design.internal.NavigationMenu
at android.support.design.widget.NavigationView.<init>(NavigationView.java:99)
at android.support.design.widget.NavigationView.<init>(NavigationView.java:92)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
[...]
这个错误使我想到了几个月前一个类似的开发人员,他们在Android 4.2.2。的某些Wiko和Samsung手机上使用了appcompat-v7库。
This error makes me think about a similar one developers had several months ago, using the appcompat-v7 library on some Wiko and Samsung phones on Android 4.2.2.
错误是:
java.lang.NoClassDefFoundError: android.support.v7.internal.view.menu.MenuBuilder
at android.support.v7.app.ActionBarActivityDelegateBase.initializePanelMenu(ActionBarActivityDelegateBase.java:914)
at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:964)
at android.support.v7.app.ActionBarActivityDelegateBase.doInvalidatePanelMenu(ActionBarActivityDelegateBase.java:1182)
at android.support.v7.app.ActionBarActivityDelegateBase.access$100(ActionBarActivityDelegateBase.java:79)
at android.support.v7.app.ActionBarActivityDelegateBase$1.run(ActionBarActivityDelegateBase.java:118)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
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:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
解决方案是在项目中使用以下proguard文件:
The solution was to use the following proguard file into the project :
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-dontobfuscate
-dontoptimize
-keep class !android.support.v7.internal.view.menu.**, ** { *; }
此解决方案很棒,因为我不必添加特定规则(只需添加一些 -dontwarn
行)作为我使用的其他库(例如Jackson)或为android组件添加特定规则。
This solution was great because I do not have to add specific rules (just some -dontwarn
lines) for other libraries I use like Jackson or to add specific rules for the android components.
因为 NavigationMenu
类继承了 MenuBuilder
类,我认为我们可以像这样修改proguard文件来解决此问题:
Because the NavigationMenu
class inherits of the MenuBuilder
class, I thought that we can modify the proguard file like this to fix the issue :
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-dontobfuscate
-dontoptimize
-keep class !android.support.design.internal.**, ** { *; }
不幸的是,它不起作用...所以我尝试了另一种解决方案:
Unfortunately it does not work... So I tried another solution :
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-dontobfuscate
-dontoptimize
-keep class !android.support.v7.internal.view.menu.*MenuBuilder*, android.support.v7.** { *; }
此解决方案可行,但是...事实上,我没有不再有 NoClassDefFoundError
异常,但我还有其他异常(在所有Android版本上都发生),如:
This solutions works but... In fact, I do not have the NoClassDefFoundError
exception anymore but I have others exceptions (that occurs on all Android versions) like :
- 一些缺少的构造函数与反射配合使用;
- 在Jackson对象或
Fragment
上缺少一些空的构造函数。
- some missing constructors use with reflection ;
- some missing empty constructors on Jackson objects or on
Fragment
.
因此,您知道一种解决方案,该解决方案允许我在Android 4.2.2上的Wiko上执行我的应用,而我没有为我使用或将来使用的每个库添加特定的规则?
So, do you know a solution that allows me to execute my app on a Wiko on Android 4.2.2 and in which one I do not have to add specific rules for each library I use or will use in the future ?
在此先感谢您的帮助!
推荐答案
感谢Szymon Klimaszewski的帮助!这是对我有用的proguard文件:
Thx for Szymon Klimaszewski for the help ! Here the proguard file that works for me :
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-dontobfuscate
-dontoptimize
-repackageclasses ''
#Jackson
-dontwarn com.fasterxml.jackson.databind.**
#View Pager Indicator
-dontwarn com.viewpagerindicator.**
#Android
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v7.app.** { *; }
-keep interface android.support.v7.app.** { *; }
-keep class android.support.v13.app.** { *; }
-keep interface android.support.v13.app.** { *; }
#droid4me
-keep class com.smartnsoft.** { *; }
#my app
-keep class my.app.package.** { *; }
#Critercism
-keep public class com.crittercism.**
-keepclassmembers public class com.crittercism.* { *; }
这篇关于NoClassDefFoundError:Android 4.2.2上的android.support.design.internal.NavigationMenu(Wiko)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!