Android 2.3 code obfuscation proguard Technology Introduction

Source: Internet
Author: User

Due to the proliferation of various decompilation tools, Android programmers can only manually add proguard Before Version 2.3 to achieve code obfuscation.

 

Proguard is a Java code obfuscation tool.

 

In SDK 2.3, we can see that a proguard folder is added under Android-SDK-Windows/tools /.

Google has put proguard Technology in the android SDK, so that code obfuscation can be achieved through normal compilation.

 

You can see that the new project contains default. properties and proguard. cfg.

 

The default. properties code is as follows:

# This file is automatically generated by Android tools. <br/> # do not modify this file -- your changes will be erased! <Br/> # This file must be checked in version control systems. <br/> # to customize properties used by the ant build system use, <br/> # "build. properties ", and override values to adapt the script to your <br/> # project structure. <br/> # project target. <br/> Target = Android-9 <br/> 

We can see that proguard. cfg has helped us write the optimization code script.

-Optimizationpasses 5 <br/>-dontusemixedcaseclassnames <br/>-dontskipnonpubliclibraryclasses <br/>-dontpreverify <br/>-verbose <br/>-optimizations! Code/simplification/arithmetic ,! Field /*,! Class/merging/* <br/>-keep public class * extends android. app. activity <br/>-keep public class * extends android. app. application <br/>-keep public class * extends android. app. service <br/>-keep public class * extends android. content. broadcastreceiver <br/>-keep public class * extends android. content. contentprovider <br/>-keep public class COM. android. vending. licensing. ilicensingservice <br/>-keepclasseswithmembernames class * {<br/> native <Methods>; <br/>}< br/>-keepclasseswithmembernames class * {<br/> Public <init> (Android. content. context, android. util. attributeset); <br/>}< br/>-keepclasseswithmembernames class * {<br/> Public <init> (Android. content. context, android. util. attributeset, INT); <br/>}< br/>-keepclassmembers Enum * {<br/> Public static ** [] values (); <br/> Public static ** valueof (Java. lang. string); <br/>}< br/>-keep class * implements android. OS. parcelable {<br/> Public static final android. OS. parcelable $ creator *; <br/>}< br/> 

From the script, we can see that the obfuscation retains the basic components inherited from activity, service, application, broadcastreceiver, contentprovider, and COM. Android. Vending. Licensing. ilicensingservice.

 

All native variable names and class names are retained. All classes Use constructors with fixed parameter formats, such as enumeration. (For more information, see examples and comments in <proguard_path>/examples .)

 

Next, follow the instructions in the Google help document.

To enable proguard so that it runs as part of an ant or eclipse build, set the proguard. config property in the <project_root>/default. properties file. the path can be an absolute path or a path relative to the project's root. 

So we modify the default. properties file.

Add the last sentence

Proguard. Config = proguard. cfg

As follows:

# This file is automatically generated by Android tools. <br/> # do not modify this file -- your changes will be erased! <Br/> # This file must be checked in version control systems. <br/> # to customize properties used by the ant build system use, <br/> # "build. properties ", and override values to adapt the script to your <br/> # project structure. <br/> # project target. <br/> Target = Android-9 <br/> proguard. config = proguard. CFG <br/> 

 

Then compile the signature normally.

 

Then, use Android tools to generate a published APK.

 

Use the decompilation tool to view the DEX file.

Finally, the obfuscation code after decompilation is exported as shown in Figure

 

 

 

Is it easy and enjoyable! I hope all programmers can protect their android code!

 

 

 

Related Article

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.