NoClassDefFoundError: android.support.v7.internal.view.menu.MenuBuilder
As #150 from google groups 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.** { *; }
-keep interface android.support.v7.** { *; }
On which device you are facing this problem ? (Samsung/HTC etc.)
If it is Samsung,
Various Samsung phones are included older versions of the android support library in the framework or classpath. If you use the new material support library, you'll see this crash on those Samsung devices:
java.lang.NoClassDefFoundError: android.support.v7.internal.view.menu.MenuBuilder
To fix this, you must rename that class. Easiest way to do that is by running proguard. If you don't want to obfuscate, here's a 1 liner to rename just the offending classes:
-keep class !android.support.v7.internal.view.menu.**,** {*;}
There's an issue tracking this problem, but since it's really a Samsung bug, it's never going to get fixed on their end. Only way to fix it on the Google/AOSP side is to rename these internal classes.
https://code.google.com/p/android/issues/detail?id=78377
EDIT:
The solution that worked for me was (Using Proguard) to replace this:
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
with this:
# Allow obfuscation of android.support.v7.internal.view.menu.**
# to avoid problem on Samsung 4.2.2 devices with appcompat v21
# see https://code.google.com/p/android/issues/detail?id=78377
-keep class !android.support.v7.internal.view.menu.**,android.support.** {*;}
Credit goes to the google group, #138.
Old answer (Temporary Workaround):
It happens in a project where I use an spinner in the ActionBar. My solution was to check for those conditions and change the app flow:
public static boolean isSamsung_4_2_2() {
String deviceMan = Build.MANUFACTURER;
String deviceRel = Build.VERSION.RELEASE;
return "samsung".equalsIgnoreCase(deviceMan) && deviceRel.startsWith("4.2.2");
}
Then in the activity's onCreate method:
if (isSamsung_4_2_2()) {
setContentView(R.layout.activity_main_no_toolbar);
} else {
setContentView(R.layout.activity_main);
}
As pointed out this is not a definitive solution, it is just a way to allow users to have access to limited functionality while a more permanent solution is found.