9

我已經實現與4.2.2手機上https://code.google.com/p/android/issues/detail?id=78377上市這一問題的許多解決方案之一後,但現在我已經更新以支持工具23,問題已經恢復。如果你看一下這個問題報告,你會看到很多人在更新後遇到同樣的問題。在NoClassDefFoundError: android.support.v7.internal.view.menu.MenuBuilder該解決方案還不能工作,因爲他們來自https://code.google.com/p/android/issues/detail?id=78377再次得到java.lang.NoClassDefFoundError:android.support.v7.internal.view.menu.i更新到支持工具23

這是我收到的例外:

java.lang.NoClassDefFoundError: android.support.v7.internal.view.menu.i 
     at android.support.v7.widget.ActionMenuView.getMenu(ActionMenuView.java:643) 
     at android.support.v7.widget.Toolbar.ensureMenu(Toolbar.java:876) 
     at android.support.v7.widget.Toolbar.getMenu(Toolbar.java:847) 
     at android.support.v7.internal.widget.ToolbarWidgetWrapper.getMenu(ToolbarWidgetWrapper.java:702) 
     at android.support.v7.internal.app.ToolbarActionBar.getMenu(ToolbarActionBar.java:583) 
     at android.support.v7.internal.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:441) 
     at android.support.v7.internal.app.ToolbarActionBar$1.run(ToolbarActionBar.java:65) 
     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776) 
     at android.view.Choreographer.doCallbacks(Choreographer.java:579) 
     at android.view.Choreographer.doFrame(Choreographer.java:547) 
     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762) 
     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(Method.java) 
     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(NativeStart.java) 

我的ProGuard有這樣的:

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

任何解決方案?得到很多用戶的投訴。

+0

我也仍然有增加,經過同樣的問題。運行4.2.2的設備 – Mikey

回答

5

您的ProGuard「keep class」規則需要更新,因爲目標類不再被混淆。在支持工具的第23版中,Google將與菜單相關的類從內部包中移出。我可以確認以下ProGuard規則消除了在運行Android 4.2.2的某些三星設備上看到的NoClassDefFoundError。

# Workaround for conflict with certain OEM-modified versions of the Android appcompat 
# support libs, especially Samsung + Android 4.2.2 
# See this thread for more info: 
# 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 
-keepattributes ** 
# Keep all classes except the ones indicated by the patterns preceded by an exclamation mark 
-keep class !android.support.v7.view.menu.**,!android.support.design.internal.NavigationMenu,!android.support.design.internal.NavigationMenuPresenter,!android.support.design.internal.NavigationSubMenu,** {*;} 
# Skip preverification 
-dontpreverify 
# Specifies not to optimize the input class files 
-dontoptimize 
# Specifies not to shrink the input class files 
-dontshrink 
# Specifies not to warn about unresolved references and other important problems at all 
-dontwarn ** 
# Specifies not to print notes about potential mistakes or omissions in the configuration, such as 
# typos in class names or missing options that might be useful 
-dontnote ** 

我強烈建議您使用dex2jar和JD確認所需的混淆已經發生了(這裏說明:https://stackoverflow.com/a/10191338/315702)。不幸的是,這應該在每次升級支持工具時完成,以防再次移動或重命名包。

Google將類從「內部」包中移出,希望避免導致NoClassDefFoundError的類路徑衝突。然而,隨着克里斯詛咒了這個bug(https://code.google.com/p/android/issues/detail?id=78377)的線程上說,他們沒有測試,以驗證修復 - 和很多人都因爲報道你看到了同樣的崩潰:

Right, we've decided to do a one-time rename of the internal classes which should fix this. I have done no testing on those devices though, and don't plan on doing any either.

相關問題