Android Proguard:发布build Force Close

时间:2015-09-16 14:16:46

标签: android forceclose android-proguard release-builds

我通过启用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$1.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);
}

1 个答案:

答案 0 :(得分:1)

问题是ShareActionProvider被剥离/混淆,但支持库需要它保持原样。

将此行添加到您的proguard配置中,您应该设置:

-keep class android.support.v7.widget.ShareActionProvider { *; }