Programming

NoClassDefFoundError : android.support.v7.internal.view.menu.MenuBuilder

procodes 2020. 5. 25. 21:21
반응형

NoClassDefFoundError : android.support.v7.internal.view.menu.MenuBuilder


Android 4.2를 실행하는 Samsung 장치의 Android appcompat v7 라이브러리에 문제가 있습니다. 개발자 콘솔에서 다음 스택 추적으로 계속 충돌이 발생합니다.

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 행입니다.

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

충돌은 일련의 장치에서 발생하지만 항상 Samsung이며 항상 Android 4.2입니다.

빠른 웹 검색을 통해 많은 사람들이 같은 문제를 겪고 있다고 믿게되었으며,이 문제를 해결하기 위해 시도한 몇 가지 단계는 다음과 같습니다.

  • Android 프로젝트 특성을 확인하고 appcompat 라이브러리가 올바르게 추가되었는지 확인하십시오.
  • Java 빌드 경로 순서 및 내보내기 프로젝트 특성을 확인하고 Android 종속성 및 Android 개인 라이브러리가 선택되어 있는지 확인하십시오.
  • 클래스가 라이브러리에 포함되어 있는지 확인하십시오 (android.support.v7.internal.view.menu.MenuBuilder).
  • R.java가 android.support.v7.appcompat의 gen 디렉토리에 있는지 확인하십시오.
  • AppCompat 테마가 Manifest.xml 활동에 포함되어 있는지 확인하십시오.
  • 프로젝트를 정리하고 다시 빌드하십시오.

이러한 단계에도 불구하고 다른 모든 장치 및 Android 버전에서 작동하더라도 충돌 보고서는 계속 발생합니다.


편집하다:

나를 위해 일한 해결책은 (Proguard 사용)이 이것을 대체하는 것입니다.

-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 에서 스피너를 사용하는 프로젝트에서 발생 합니다 . 내 솔루션은 이러한 조건을 확인하고 앱 흐름을 변경하는 것이 었습니다.

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 메소드에서 :

if (isSamsung_4_2_2()) {
    setContentView(R.layout.activity_main_no_toolbar);
} else {
    setContentView(R.layout.activity_main);
}

이 솔루션은 결정적인 솔루션이 아니라보다 영구적 인 솔루션을 찾는 동안 사용자가 제한된 기능에 액세스 할 수 있도록하는 방법 일뿐입니다.


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


This issue returned in AppCompat 23.1.1 where the .internal package was removed from the library jar.

As suggested in the comments above (credits to the people who suggested it there), now also the proguard configuration has to change.

To get the answer suggested above working again, try adding these lines to your proguard files:

#FOR APPCOMPAT 23.1.1:
-keep class !android.support.v7.view.menu.*MenuBuilder*, android.support.v7.** { *; }
-keep interface android.support.v7.* { *; }

In stead of the old fix:

#FOR OLDER APPCOMPAT VERSION:
-keep class !android.support.v7.internal.view.menu.*MenuBuilder, android.support.v7.** { ; }
-keep interface android.support.v7.* { *; }

According to the last posts of the bug-report, this should be fixed on the new version of the support library (24.0.0) : https://code.google.com/p/android/issues/detail?id=78377#c374

Someone even claimed it fixed it.

This version is available since last month, so you should update to it.


Yes. Samsung already knows about this problem. I can suggest you try to using same implementation of Popup from GitHub. It is not best way, but will be works.


I was having the same problem of this MenuBuilder class not found in USB debugging mode. I solved this problem by simply setting the minifyEnabled to true in both release and debug buildTypes block of build.gradle . like this:

buildTypes {

    debug {

        minifyEnabled true
    }

    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

I set the minifyEnabled to true in debug type to prevent app from crashing via USB debugging to a live handset.


I enabled proguard with the default proguard properties provided with an eclipse project and the problem was fixed for me. Based on some comments here https://code.google.com/p/android/issues/detail?id=78377 , some people might have to repackage using: -repackageclasses "android.support.v7"


I got the same error when trying to run a 'Hello World' app on my Samsung Galaxy Tab 3 tablet via Android Studio. The app would appear to launch and then it would crash instantly and that error would show in the console in Android Studio. I did a system update on the tablet and now I am able to run the 'Hello World' app and I'm not getting the error anymore. I hope this helps someone to resolve their issue.

Note: The system update I performed on the tablet did not update the Android OS version, because it still says that the version is 4.2.2.


Change the Compile Sdk Version of your project to "API 18:(JellyBean)"

The default is set to "Lollipop

STEPS

  1. Right Click on your project and select Open Module Settings (or press F4)
  2. In the properties tab Compiled Sdk Version

참고URL : https://stackoverflow.com/questions/24809580/noclassdeffounderror-android-support-v7-internal-view-menu-menubuilder

반응형