NoClassDefFoundError: android.support.design.internal.NavigationMenu on Android 4.2.2 (wiko)
Asked Answered
P

5

10

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

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 !

Polyclinic answered 22/9, 2015 at 18:6 Comment(0)
P
-4

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.* { *; }
Polyclinic answered 23/9, 2015 at 14:9 Comment(1)
There's a whole lot of stuff in this config file that might have nothing to do with this issue. Could you be more specific as to what exactly is curing this problem with the NavigationView? I want obfuscation for example and won't switch it off - I do not believe this has to do with the problem...Adherence
H
5

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.** { *; }
Hereafter answered 23/9, 2015 at 11:3 Comment(5)
Thx for your answer. I tried your solution. I do not have the NoClassDefFoundError exception but I have other exceptions like: ``` Caused by: java.lang.NoSuchMethodException: <init> [class java.lang.String, int] at java.lang.Class.getConstructorOrMethod(Class.java:460) at java.lang.Class.getDeclaredConstructor(Class.java:588) at com.smartnsoft.droid4me.cache.Persistence.getInstance(Persistence.java:460) ``` Do you know a solution that fixes the NoClassDefFoundError exception and in which one you do not have to add rules for each library used in the project ?Polyclinic
repackageclasses breaks most reflection that is used in your code. You would need to add to the config: -keep class your.package.name.** { *; }Hereafter
Thx ! It seems to work. I am going to post the full proguard file as an answer.Polyclinic
Great! Two more things. 1- try to build without -allowaccessmodification flag. It's risky and may affect logic in very rare cases 2- Mark your answer as the right one so that other people will know what to look at :)Hereafter
It works well without the allowaccessmodification flag. Thx again for your help :) I'm going to mark my answer as the right one as some as it is possible (11 hours left...)Polyclinic
G
0

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.** {*;}
Geez answered 6/1, 2016 at 21:18 Comment(0)
A
-1

-

   -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.** { *; }
Acerbic answered 18/2, 2016 at 13:37 Comment(0)
D
-1

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

Darryldarryn answered 4/4, 2016 at 15:33 Comment(0)
P
-4

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.* { *; }
Polyclinic answered 23/9, 2015 at 14:9 Comment(1)
There's a whole lot of stuff in this config file that might have nothing to do with this issue. Could you be more specific as to what exactly is curing this problem with the NavigationView? I want obfuscation for example and won't switch it off - I do not believe this has to do with the problem...Adherence

© 2022 - 2024 — McMap. All rights reserved.