0

I generated release build by enabling minifyEnabled property and when I try to run the release build, it force closes with following log. Please help me to debug it

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)

This is my code for 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);
}
Harsh
  • 644
  • 3
  • 14
  • 27
  • Can you use the mapping file created by ProGuard to decode the obfuscated stack trace? This will help identify the line that is crashing. You can find instructions here: http://developer.android.com/tools/help/proguard.html in the "Decoding Obfuscated Stack Traces" section – Matthew Horst Sep 16 '15 at 14:18
  • Your log clearly indicates the issue is happening in `onCreateOptionsMenu()` in your `MainActivity`. Please post that portion of your code. – Bryan Herbst Sep 16 '15 at 14:19
  • @Tanis.7x I've added that code. But logcat does not point to any line number. – Harsh Sep 16 '15 at 14:43
  • @MattHorst , what input I should pass for this [] ? – Harsh Sep 16 '15 at 14:51
  • Looks like Tanis.7x already solved the question. But for any future reference, the file you would pass is created as part of the build process, whenever ProGuard in used in your build process (e.g. creating a Release build). The file is by default placed here: .../build/outputs/mapping/release/mapping.txt – Matthew Horst Sep 16 '15 at 17:42

1 Answers1

1

The problem is that ShareActionProvider is being stripped/obfuscated, but the support library needs it to remain as-is.

Add this line to your proguard configuration, and you should be set:

-keep class android.support.v7.widget.ShareActionProvider { *; }
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120