NoClassDefFoundError:android.support.v7.internal.view.menu.MenuBuilder [英] NoClassDefFoundError: android.support.v7.internal.view.menu.MenuBuilder

查看:25
本文介绍了NoClassDefFoundError:android.support.v7.internal.view.menu.MenuBuilder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行 Android 4.2 的三星设备上的 Android appcompat v7 库存在问题.我的开发者控制台中的以下堆栈跟踪不断导致崩溃:

There is an issue with the Android appcompat v7 library on Samsung devices running Android 4.2. I keep getting crashes with the following stack trace in my Developer Console:

java.lang.NoClassDefFoundError: android.support.v7.internal.view.menu.MenuBuilder
    at android.support.v7.widget.PopupMenu.<init>(PopupMenu.java:66)
    at com.[my-package-name].CustomActivity$5.onClick(CustomActivity.java:215)
    at android.view.View.performClick(View.java:4222)
    at android.view.View$PerformClick.run(View.java:17620)
    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)
    at dalvik.system.NativeStart.main(Native Method)

这是 CustomActivity.java 的第 215 行:

This is line 215 of CustomActivity.java:

PopupMenu popup = new PopupMenu(CustomActivity.this, mImageViewMenu);

崩溃来自一系列设备,但总是三星,总是 Android 4.2.

The crashes come from an array of devices, but always Samsung, and always Android 4.2.

快速的网络搜索让我相信很多人都有同样的问题,我尝试解决的一些步骤是:

A quick web search leads me to believe that many people have the same issue, some of the steps I have tried to solve the issue are:

  • 检查 Android 项目属性,确保正确添加了 appcompat 库.
  • 检查 Java Build Path Order 和 Export 项目属性,确保选中 Android Dependencies 和 Android Private Libraries.
  • 确认类包含在库中 (android.support.v7.internal.view.menu.MenuBuilder).
  • 确认 R.java 位于 android.support.v7.appcompat 的 gen 目录中.
  • 确认 AppCompat 主题包含在 Manifest.xml 活动中.
  • 清理并重建项目.

尽管采取了这些步骤,尽管它适用于所有其他设备和 Android 版本,但崩溃报告仍然存在.

Despite these steps, and despite it working on all other devices and Android versions the crash reports still come through.

推荐答案

对我有用的解决方案是(使用 Proguard)来代替这个:

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

这样:

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

归功于 google 组,#138.

旧答案(临时解决方法):它发生在我在 ActionBar 中使用微调器的项目中.我的解决方案是检查这些条件并更改应用流程:

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");
}

然后在活动的 onCreate 方法中:

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.

这篇关于NoClassDefFoundError:android.support.v7.internal.view.menu.MenuBuilder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆