Android Code obfuscation

Source: Internet
Author: User
Tags jboss

Obfuscation (Proguard)

The obfuscation compresses, optimizes, and confuses code by removing code that has never been used and renaming classes, fields, and methods with obscure names. The result is a smaller. apk file, which is more difficult to reverse engineer. Therefore, when your application is sensitive to security (high demand), such as when you authorize an application, the obfuscation is an important protection tool.
The obfuscation is integrated into the Android build system, so you don't have to call it manually. The obfuscation will only run when the application is built in release mode, so you don't have to deal with confusing code when building the program in debug mode. Making the obfuscation run is optional, but recommended.

  1. Modify Project.Properties
    # This file was automatically generated by Android Tools. # do not modify ThisFILE--YOUR changes'll be erased!# # This file must is checked in Version Control Systems. # to customize properties used by the Ant build system Edit #"Ant.properties", and override values to adapt the script to your # project structure. # # To enable Proguard to shrink and obfuscate your code, uncomment This(available Properties:sdk.dir, user.home): #Proguard.config =${sdk.dir}/tools/proguard/proguard-android.txt:proguard-Project.txt # project Target. Target =android-19

    Remove the comments from the front of the Proguard.config

If a third-party ' jar ' package is used in the program , causing an error after confusion, we need to configure it in proguard-project.txt so that it does not confuse the jar package when it is confused. The relevant configuration in the configuration file is explained as follows:

-keep Public class*extendsandroid.app.Activity "Do not confuse class names, keep their original class name and package name"-keep Public Abstract Interfacecom.asqw.android.listener{ Public protected<methods>; "All public protected method names are not confused"}-keep Public classcom.asqw.android{ Public voidStart (java.lang.String); "No confusion with this method"}-keepclasseswithmembernamesclass*{"Native method names are not confused for all classes"native<methods>; }    -keepclasseswithmembersclass*{"The method name of the specified method for all classes is not confused" Public<init>(Android.content.Context, Android.util.AttributeSet); }    -keepclassmembersclass*extendsandroid.app.Activity {"The method name of the specified method for all classes is not confused" Public void*(Android.view.View); }    -keepclassmembersenum*{"The method name of the following specified method is not confused for all classes of enum type enum" Public Static**[] values ();  Public Static**valueOf (java.lang.String); }    -keepclass*Implementsandroid.os.Parcelable {"Does not confuse the class name of all classes that implement the Parcelable interface and does not confuse the variable name of a member variable whose member variable is of type Parcelable$creator" Public Static FinalAndroid.os.parcelable$creator *; }    -keepclasseswithmembersclassorg.jboss.netty.util.internal.LinkedTransferQueue {"The variable name of the specified variable for the specified class is not confused"volatile transientOrg.jboss.netty.util.internal.linkedtransferqueue$node Head; volatile transientOrg.jboss.netty.util.internal.linkedtransferqueue$node Tail; volatile transient intsweepvotes; }    -keep Public classcom.unionpay.** {*;} "There is no confusion about all classes under the Com.unionpay package, that is, the class name is not confused, and the method name and the variable name are not confused"

After the above two parts after the anti-compilation can be confused, but the four components are still, why the four components are still there, because the four components are configured in the manifest file, if the confusion can not be based on the configuration of the manifest file to find.
If for some of your own code to provide a way for others to call through reflection, we do not want to let some of the code is confused, or we use other people to provide third-party jar package, because the third-party jar package is generally confused, if we are confused will be error, So we have to make sure that this is not confusing, we just need to modify the file, and then add the following sentence, he will not confuse the content we give

-keepattributes *annotation*-keep Public class*extendsandroid.app.Activity-keep Public class*extendsandroid.app.Application-keep Public class*extendsAndroid.app.Service-keep Public class*extendsAndroid.content.BroadcastReceiver-keep Public class*extendsAndroid.content.ContentProvider-keep Public class*extendsandroid.app.backup.BackupAgent-keep Public class*extendsandroid.preference.Preference-keep Public class*extendsandroid.support.v4.app.Fragment-keep Public class*extendsandroid.app.Fragment-keep Public classCom.android.vending.licensing.ILicensingService-keepclassnet.youmi.android.** {*;}

Android Code obfuscation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.