ProGuard with Android: java.lang.NoSuchMethodError: android.util.Xml.asAttributeSet

≡放荡痞女 提交于 2019-12-04 16:13:15

问题


My app runs normally when ProGuard is disabled.

After ProGuard is enabled, the app is exported into apk and installed into emulator.

Then when I run it in emulator, force close...

05-10 11:14:10.582: E/AndroidRuntime(759): FATAL EXCEPTION: main
05-10 11:14:10.582: E/AndroidRuntime(759): java.lang.NoSuchMethodError: android.util.Xml.asAttributeSet
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.actionbarsherlock.view.MenuInflater.inflate(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.g.myapp.e.onCreateOptionsMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.support.v4.app.Watson.onCreatePanelMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchInvalidateOptionsMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.actionbarsherlock.app.SherlockFragmentActivity.invalidateOptionsMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.actionbarsherlock.app.SherlockFragmentActivity.supportInvalidateOptionsMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.support.v4.app.Fragment.setHasOptionsMenu(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.g.myapp.e.onCreate(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.support.v4.app.BackStackRecord.run(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.g.myapp.n.onTabChanged(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.widget.TabHost.invokeOnTabChangeListener(TabHost.java:391)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.widget.TabHost.setCurrentTab(TabHost.java:376)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.widget.TabHost.addTab(TabHost.java:236)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.g.myapp.n.a(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.g.myapp.MainActivity.onCreate(Unknown Source)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.app.Activity.performCreate(Activity.java:5008)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.os.Looper.loop(Looper.java:137)
05-10 11:14:10.582: E/AndroidRuntime(759):  at android.app.ActivityThread.main(ActivityThread.java:4745)
05-10 11:14:10.582: E/AndroidRuntime(759):  at java.lang.reflect.Method.invokeNative(Native Method)
05-10 11:14:10.582: E/AndroidRuntime(759):  at java.lang.reflect.Method.invoke(Method.java:511)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-10 11:14:10.582: E/AndroidRuntime(759):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-10 11:14:10.582: E/AndroidRuntime(759):  at dalvik.system.NativeStart.main(Native Method)

proguard-project.txt:

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }

-keepattributes *Annotation*

-dontwarn org.w3c.dom.bootstrap.**
-dontwarn org.joda.time.**
-dontwarn org.xmlpull.v1.**

How can I fix the error?

Thank you very much!


Updated:

The app can be run in emulator after adding one line to proguard-project.txt:

-keep class * { *; }

Although the app can be run, I think this solution may be not so good...

Any better solution?

Please help.

Thanks a lot.


回答1:


add one line to proguard-project.txt:

-keep class org.xmlpull.v1.** { *; }


来源:https://stackoverflow.com/questions/16474904/proguard-with-android-java-lang-nosuchmethoderror-android-util-xml-asattribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!