Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

appcompat-v7 v21.0.0 causing crash on Samsung devices with Android v4.2.2

We just changed our application to use the appcompat-v7 support library in order to take advantage of the support actionbar and support Material themes. Using v21.0.0 of appcompat-v7 (andv21.0.0 of support-v4), we are now seeing crashes in Google Play and Crashlytics only from Samsung devicesrunningAndroid v4.2.2. Here is the stack trace from Google Play and the app appears to crash as soon as theactionbar` is shown and/or invalidated.

java.lang.NoClassDefFoundError: android.support.v7.internal.view.menu.MenuBuilder
at android.support.v7.app.ActionBarActivityDelegateBase.initializePanelMenu(ActionBarActivityDelegateBase.java:991)
at android.support.v7.app.ActionBarActivityDelegateBase.preparePanel(ActionBarActivityDelegateBase.java:1041)
at android.support.v7.app.ActionBarActivityDelegateBase.doInvalidatePanelMenu(ActionBarActivityDelegateBase.java:1259)
at android.support.v7.app.ActionBarActivityDelegateBase.access$100(ActionBarActivityDelegateBase.java:80)
at android.support.v7.app.ActionBarActivityDelegateBase$1.run(ActionBarActivityDelegateBase.java:116)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)

Other devices and emulators running v4.2.2 do no exhibit this behavior. It's my understanding that many Google apps are already using this new version of appcompat to display the action bar. If these apps are not reporting crashes on these devices, it would be helpful to know how this is being avoided/fixed.

I reported this as a bug to Google but it got closed with the reason that it is a development issue. Although I do agree this may be the case, I'm wondering if/how anyone is currently able to use appcompat-v7 v21.0.0 and not get crashes on Samsung 4.2.2 devices.

Update: It looks like Google is at least considering possible workarounds for this. See this for details.

like image 777
Erik Pedersen Avatar asked Oct 30 '14 15:10

Erik Pedersen


4 Answers

I found the proper solution here: https://stackoverflow.com/a/26641388/1266123

By using

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

instead of

-keep class android.support.v7.** {*;} 
like image 151
robUx4 Avatar answered Sep 21 '22 10:09

robUx4


As #150 from https://code.google.com/p/android/issues/detail?id=78377 said

Because careful with -keep class !android.support.v7.internal.view.menu.**. There are a number of classes in there which are referenced from the appcompat's resources.

The better solution is add the following lines instead:

-keep class !android.support.v7.internal.view.menu.MenuBuilder, !android.support.v7.internal.view.menu.SubMenuBuilder, android.support.v7.** { *; } -keep interface android.support.v7.** { *; } 
like image 34
Pongpat Avatar answered Sep 21 '22 10:09

Pongpat


Since Appcompat 23.1.1 the .internal package in the AppCompat jar was removed.

Updated fix using proguard:

#FOR APPCOMPAT 23.1.1:
-keep class !android.support.v7.view.menu.*MenuBuilder*, android.support.v7.** { *; }
-keep interface android.support.v7.* { *; }
like image 34
RWIL Avatar answered Sep 22 '22 10:09

RWIL


For all having this problem, only workaround so far seems to be using proguard. Checkout discussion at https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=78377

like image 34
Martin Vandzura Avatar answered Sep 21 '22 10:09

Martin Vandzura