Search code examples
androiddexguard

onClick() does not work after appying dexguard. Is there any way to solve this?


i am using dexguard to secure my app. Recently i updated the dexgaurd version from 8.0.1 to 8.2.15. Earlier everything is working fine before the update. But with the version 8.2.15 when i apply dexguard, onCick method does not works in one of fragment SettingsFragment, for all of the other Fragments it works fine. However the code and method of implementing onClick() is same for all Fragments. But for SettingsFragment it's not working. Please help.

Here is my onClick method in SettingsFragment

View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.relSignOut:
                    mCallback.doSignOut();
                    break;
//                case R.id.relEditProfile:
//                    loadManageProfile();
//                    break;
                case R.id.btn_edit_profile:
                    loadManageProfile();
                    break;
                case R.id.relDynamicFxRate:
                    parent.startSetExchangeAlertActivity();
                    break;
            }
        }
    };

Thanks in Advance


Solution

  • (Converting my comment to answer)

    Please kick off the switch statement and replace it with if-else. May seem bit unscientific and illogical, but I worked for me many times.

    I don't know if it's a possible bug in the compiler or in Android or not, but sometimes rejecting switch statement only doesn't help. Then I've to replace view.getId() with view.getPosition() and check by order or something like this to make it work anyway.

    From T.Neidhart's comment: The reason it fails is probably due to resource optimization which remaps resource IDs. Normally these remapped resource IDs get replaced everywhere in the code, but it might go wrong in case of switch statements. You can disable resource optimization like that: -optimizations resource/compaction –