android - POPUPMENU icon is not getting displayed in released apk version -


i'm following tutorial , works fine when i'm in debugging mode when generate apk in release mode icons won't work mean won't appear why??

here link tutorial following tutorial here

custom_menu.xml

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">  <item android:id="@+id/....."     android:title="------"     android:icon="....."     app:showasaction="always"/>  <item android:id="@+id/....."     android:title="------"     android:icon="....."     app:showasaction="always"/>  <item android:id="@+id/....."     android:title="------"     android:icon="....."     app:showasaction="always"/> <item android:id="@+id/....."     android:title="------"     android:icon="....."     app:showasaction="always"/> </menu> 

and here java code

  view menuitemview = getactivity().findviewbyid(r.id.overflow);             popupmenu popupmenu = new popupmenu(getactivity(), menuitemview);             popupmenu.inflate(r.menu.custom_menu);             //             object menuhelper;             class[] argtypes;             field fmenuhelper = null;             try {                 fmenuhelper = popupmenu.class.getdeclaredfield("mpopup");                 fmenuhelper.setaccessible(true);                 menuhelper = fmenuhelper.get(popupmenu);                 argtypes = new class[]{boolean.class};                 menuhelper.getclass().getdeclaredmethod("setforceshowicon", argtypes).invoke(menuhelper, true);             } catch (nosuchfieldexception e) {                 e.printstacktrace();             } catch (invocationtargetexception e) {                 e.printstacktrace();             } catch (nosuchmethodexception e) {                 e.printstacktrace();             } catch (illegalaccessexception e) {                 e.printstacktrace();             } 

this happens because proguard obfuscates popupmenu class name. make icons work in release apk, include following code proguard.cfg file:

-keepclassmembernames class android.support.v7.widget.popupmenu { private android.support.v7.internal.view.menu.menupopuphelper mpopup; }  -keepclassmembernames class android.support.v7.internal.view.menu.menupopuphelper { public void setforceshowicon(boolean); } 

Comments