android 4.2 noclassdeffounderror,NoClassDefFoundError: android.support.design.internal.NavigationMen...

问题

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).

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

[...]

Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class

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.(NavigationView.java:99)

at android.support.design.widget.NavigationView.(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)

[...]

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.

The error was :

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)

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.**, ** { *; }

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.

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.** { *; }

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 :

some missing constructors use with reflection ;

some missing empty constructors on Jackson objects or on Fragment.

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 ?

Thank you in advance for your help !

回答1:

I'm following similar thread and struggling with finding the solution, but I don't have a device.

Basing on people's comments I have added following to the proguard config

build type:

buildTypes {

release {

minifyEnabled true

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'

}

}

proguard-project.txt

-repackageclasses ''

-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.** { *; }

Could you please try with the following config?

I have some doubts to this solution, because when I have undexed produced classes I still had NavigationMenuView in the same package. It hasn't been moved because of it's package access relationships. So what may help is adding another flag to the proguard-project.txt config, quite risky though:

-allowaccessmodification

That may be a good start to try fixing the issue.

So in your case proguard-project should look like this:

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-dontobfuscate

-dontoptimize

-allowaccessmodification

-repackageclasses ''

-keep class your.package.name.** { *; }

-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.** { *; }

回答2:

I'm going with this. I haven't tried it yet, since I don't have any of the affected devices:

-keep class !android.support.design.internal.NavigationMenu,!android.support.design.internal.NavigationMenuPresenter,!android.support.design.internal.NavigationSubMenu

That goes in addition to this rule that helps many Samsung devices (see http://goo.gl/ywG1c4):

-keep class !android.support.v7.view.menu.**,android.support.** {*;}

回答3:

-

-keep class !android.support.v7.internal.view.menu.**,** {*;}

-keep class android.support.v4.** { *; }

-keep interface android.support.v4.** { *; }

-keep class android.support.v7.** { *; }

-keep interface android.support.v7.** { *; }

回答4:

Check com.android.support:appcompat version. For example,

instead of com.android.support:appcompat-v7:23.1.1 try to use com.android.support:appcompat-v7:23.0.1

回答5:

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.* { *; }

来源:https://stackoverflow.com/questions/32723868/noclassdeffounderror-android-support-design-internal-navigationmenu-on-android

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值