Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proguard issues with code obfuscation #66

Closed
wmontwe opened this issue Oct 30, 2015 · 4 comments
Closed

Proguard issues with code obfuscation #66

wmontwe opened this issue Oct 30, 2015 · 4 comments

Comments

@wmontwe
Copy link

wmontwe commented Oct 30, 2015

We enabled code obfuscation for our project and had issues with provided proguard config. We had to add -keepnames class * { @icepick.State *;} to properly run our app.

-dontwarn icepick.**
-keep class **$$Icepick { *; }
-keepnames class * { @icepick.State *;}
-keepclasseswithmembernames class * {
    @icepick.* <fields>;
}
@frankiesardo
Copy link
Owner

This seems in direct contrast with issue #63

I don't have the time or energy to get to the bottom of this so if you have more info that's definitely appreciated!

@hkurokawa
Copy link

@frankiesardo Hi, I encountered the exact same problem and adding -keepnames class * { @icepick.State *;} resolved the issue.

I know there is another conflicting issue #63 but I guess if someone wants to use -repackageclasses option, it is his liability to tweak the proguard rules to make it work. I strongly believe it's better to add the line to the README as this problem would be very popular.

Here is the detailed reproducing steps:
1: Enable Proguard (shrinking and obfuscation are both enabled)
2: Add the below lines in build.gradle to install Icepick

    compile 'frankiesardo:icepick:3.2.0'
    apt 'frankiesardo:icepick-processor:3.2.0'

3: Create a Fragment which takes advantage of Icepick like below

package hkurokawa.icepickSample.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import butterknife.OnClick;
import icepick.Icepick;
import icepick.State;
import hkurokawa.icepickSample.R;

import android.net.Uri;
import android.view.View;

import java.util.ArrayList;

public class SampleFragment extends Fragment {
   private static final int REQUEST_CODE_SOME = 101;
    @State
    ArrayList<Uri> uris = new ArrayList<>();

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Icepick.restoreInstanceState(this, savedInstanceState);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Icepick.setDebug(true);
        Icepick.saveInstanceState(this, outState);
        Icepick.setDebug(false);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case REQUEST_CODE_SOME:
                 Uri a = uris.get(0);
                 break;
        }
    }

    @OnClick(R.id.btn)
    void onClickBtn(View button) {
        uris.add(Uri.parse("https://github.com/frankiesardo/icepick"));
        Intent intent = SomeActivity.createIntent(getActivity());
        startActivityForResult(intent, REQUEST_CODE_SOME);
    }
    ...
}

3: Build the app and run it with a Debug option "Don't keep activities" on
4: When I clicked a button to open another activity from the Fragment, I saw the below adb logs.

04-29 16:39:37.491 11834-11834/hkurokawa.icepickSample D/Icepick: Not found. Trying superclass android.support.v4.app.aa
04-29 16:39:37.491 11834-11834/hkurokawa.icepickSample D/Icepick: MISS: Reached framework class. Abandoning search.

5: I found the uris are not restored in onActivityCreated() which caused IndexOutOfBoundsException problem when I backed to the Fragment and tried to use the field.

If you need further information, please let me know.

Thank you.

@frankiesardo
Copy link
Owner

You make a very good point, thanks for supporting your reasoning with an example.

I've updated the master README including the keepnames

@hkurokawa
Copy link

Thank you for your prompt action. Appreciate your support and providing this great library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants