Android adt uses proguard to make obfuscated package specific steps [detailed]

[Original by Bluecoffee] Please indicate the source for reprinting!

To make an obfuscated package, there are a total of several steps:

Step 1: Export the Java code in the Android project as a Jar package.

Export method: the directory under src, right-click and select Export, as shown in the figure below, select the export jar package

Enter image description

next Next step, note that the folders under src should be checked, as shown in the following figure,

Enter image description

finish, the export of the jar package is successful. If you are worried about whether the classes in the jar package are complete, you can use the jd-gui tool to decompile to check.

The second step: copy a same project (you can copy it to another workspace) , delete all the java classes under src, put the jar package exported in the first step under lib, run the app to see if the function is normal. If it is normal, please go to the third step. If it is not normal, please go back to the first step to check whether any classes have not been exported successfully.

The third step: the main event is coming, use proguard to obfuscate the jar package exported in the first step.

where is the proguard? Please refer to "Your sdk path\tools\proguard", the proguard tool is already in the sdk, and there is no need to download it separately. Under proguard\bin, run proguardgui.bat, as shown below:

Enter image description

Click Load Configuration, load into a file, and write the classes that need keep in it. Below, I give an example:

-injars 第一步的jar包.jar

-outjars 导出的jar包.jar

-libraryjars '你的项目路径\libs\android-support-v4.jar'

-libraryjars '你的jdk路径\jdk1.6.0_37'

-libraryjars '你的sdk路径\platforms\android-21'

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-optimizationpasses 5
-printmapping mapping.txt
-dontusemixedcaseclassnames
-keepattributes *Annotation*,Signature
-dontpreverify
-verbose
-dontwarn com.alipay.android.phone.mrpc.core**,com.alipay.apmobilesecuritysdk.face**,cn.jpush**,com.lidroid**,com.sinovoice**,com.baidu**,com.android.volley.toolbox**,com.google.gson**,org.apache.http**,com.handmark.pulltorefresh**,com.squareup.picasso**,com.cheweishi.android.entity**


-keep class * extends java.lang.annotation.Annotation {
    <fields>;
    <methods>;
}

-keep public class * extends android.app.Fragment

-keep public class * extends android.app.Activity

-keep public class * extends android.app.Application

-keep public class * extends android.app.Service

-keep public class * extends android.content.BroadcastReceiver

-keep public class * extends android.content.ContentProvider

-keep public class * extends android.app.backup.BackupAgentHelper

-keep public class * extends android.preference.Preference

-keep public class * extends android.support.v4.**

-keep public class * extends android.support.v7.**

-keep class com.alipay.android.phone.mrpc.core.** {
    <fields>;
    <methods>;
}

-keep class com.alipay.apmobilesecuritysdk.face.** {
    <fields>;
    <methods>;
}

-keep class cn.jpush.** {
    <fields>;
    <methods>;
}

-keep class com.lidroid.** {
    <fields>;
    <methods>;
}

# 自定义控件不需要混淆
-keep class com.cheweishi.android.widget.** {
    <fields>;
    <methods>;
}

-keep class com.sinovoice.** {
    <fields>;
    <methods>;
}

-keep class com.baidu.** {
    <fields>;
    <methods>;
}

-keep class vi.com.gdi.bgl.android.** {
    <fields>;
    <methods>;
}

-keep class com.android.volley.toolbox {
    <fields>;
    <methods>;
}

-keep class com.google.gson.** {
    <fields>;
    <methods>;
}

-keep class org.apache.http.** {
    <fields>;
    <methods>;
}

-keep class com.handmark.pulltorefresh.** {
    <fields>;
    <methods>;
}

-keep class com.squareup.picasso.** {
    <fields>;
    <methods>;
}

-keep class com.cheweishi.android.entity.** {
    <fields>;
    <methods>;
}

-keep class com.cheweishi.android.response.BaseResponse

-keep public class com.android.vending.licensing.ILicensingService

-keep class * extends android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}

-keepclasseswithmembers,allowshrinking class * {
    public <init>(android.content.Context,android.util.AttributeSet);
}

-keepclasseswithmembers,allowshrinking class * {
    public <init>(android.content.Context,android.util.AttributeSet,int);
}

# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum  * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,allowshrinking class * {
    native <methods>;
}

Please replace the Chinese character path by yourself. If the files are all changed correctly, you can click the next button all the way. If some parts need to be modified, you can modify the configuration one by one next, for example:

Enter image description

In the second tab input and output, you can modify the imported and exported jar paths and the dependent class library paths. Next, you can also configure the paths that require keep, so I won't repeat them.

Finally, go to the process tab and click Process! , the confusion begins. After a bunch of logs, the confusion ends. Note: In the log, there is no problem at the Note level. If there are logs such as warn and error, then there is a problem. Please modify the configuration according to the error prompt.

Step 4: Close to Success! Put the obfuscated exported jar package into the copy project in the second step, and don't forget to delete the original tested jar package.

Next run the app and see if the obfuscated app works. Using jd-gui to see how readable the obfuscated jar package is, it must look like you want to cry, that's right, you're done!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325461817&siteId=291194637