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 !