Android Proguard:发布构建强制关闭
Android Proguard: Release build Force Close
我通过启用 minifyEnabled 属性 生成了发布版本,当我尝试 运行 发布版本时,它强制关闭并显示以下日志。
请帮我调试一下
java.lang.NullPointerException
at MYPACKAGENAME.MainActivity.onCreateOptionsMenu(Unknown Source)
at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
at android.support.v4.app.i.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.view.j.onCreatePanelMenu(Unknown Source)
at android.support.v7.app.ac.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.view.j.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.a.b.f(Unknown Source)
at android.support.v7.internal.a.b.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
这是我的 onCreateOptionsMenu 方法代码
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
//Set up ShareActionProvider's default share intent
MenuItem shareItem = menu.findItem(R.id.action_share_main);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
mShareActionProvider.setShareIntent(getDefaultIntent());
return super.onCreateOptionsMenu(menu);
}
问题是 ShareActionProvider
正在 stripped/obfuscated,但支持库需要它保持原样。
将此行添加到您的混淆器配置中,您应该设置为:
-keep class android.support.v7.widget.ShareActionProvider { *; }
我通过启用 minifyEnabled 属性 生成了发布版本,当我尝试 运行 发布版本时,它强制关闭并显示以下日志。 请帮我调试一下
java.lang.NullPointerException
at MYPACKAGENAME.MainActivity.onCreateOptionsMenu(Unknown Source)
at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
at android.support.v4.app.i.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.view.j.onCreatePanelMenu(Unknown Source)
at android.support.v7.app.ac.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.view.j.onCreatePanelMenu(Unknown Source)
at android.support.v7.internal.a.b.f(Unknown Source)
at android.support.v7.internal.a.b.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
这是我的 onCreateOptionsMenu 方法代码
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
//Set up ShareActionProvider's default share intent
MenuItem shareItem = menu.findItem(R.id.action_share_main);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
mShareActionProvider.setShareIntent(getDefaultIntent());
return super.onCreateOptionsMenu(menu);
}
问题是 ShareActionProvider
正在 stripped/obfuscated,但支持库需要它保持原样。
将此行添加到您的混淆器配置中,您应该设置为:
-keep class android.support.v7.widget.ShareActionProvider { *; }