Android 2.3 code obfuscation proguard technology Overview

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:

View plaincopy to clipboardprint?
# This file is automatically generated by Android tools.
# Do not modify this file -- your changes will be erased!
#
# This file must be checked in version control systems.
#
# To customize properties used by the ant build system use,
# "Build. properties", and override values to adapt the script to your
# Project structure.
# Project target.
Target = Android-9
# This file is automatically generated by Android tools.
# Do not modify this file -- your changes will be erased!
#
# This file must be checked in version control systems.
#
# To customize properties used by the ant build system use,
# "Build. properties", and override values to adapt the script to your
# Project structure.
# Project target.
Target = Android-9
 

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

View plaincopy to clipboardprint?
-Optimizationpasses 5
-Dontusemixedcaseclassnames
-Dontskipnonpubliclibraryclasses
-Dontpreverify
-Verbose
-Optimizations! Code/simplification/arithmetic ,! Field /*,! Class/merging /*
-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 com. Android. Vending. Licensing. ilicensingservice
-Keepclasseswithmembernames class *{
Native <Methods>;
}
-Keepclasseswithmembernames class *{
Public <init> (Android. content. Context, Android. util. attributeset );
}
-Keepclasseswithmembernames class *{
Public <init> (Android. content. Context, Android. util. attributeset, INT );
}
-Keepclassmembers Enum *{
Public static ** [] values ();
Public static ** valueof (Java. Lang. String );
}
-Keep class * implements Android. OS. parcelable {
Public static final Android. OS. parcelable $ creator *;
}
-Optimizationpasses 5
-Dontusemixedcaseclassnames
-Dontskipnonpubliclibraryclasses
-Dontpreverify
-Verbose
-Optimizations! Code/simplification/arithmetic ,! Field /*,! Class/merging /*
-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 com. Android. Vending. Licensing. ilicensingservice
-Keepclasseswithmembernames class *{
Native <Methods>;
}
-Keepclasseswithmembernames class *{
Public <init> (Android. content. Context, Android. util. attributeset );
}
-Keepclasseswithmembernames class *{
Public <init> (Android. content. Context, Android. util. attributeset, INT );
}
-Keepclassmembers Enum *{
Public static ** [] values ();
Public static ** valueof (Java. Lang. String );
}
-Keep class * implements Android. OS. parcelable {
Public static final Android. OS. parcelable $ creator *;
}
 

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.

View plaincopy to clipboardprint?
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.
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:

View plaincopy to clipboardprint?
# This file is automatically generated by Android tools.
# Do not modify this file -- your changes will be erased!
#
# This file must be checked in version control systems.
#
# To customize properties used by the ant build system use,
# "Build. properties", and override values to adapt the script to your
# Project structure.
# Project target.
Target = Android-9
Proguard. Config = proguard. cfg
# This file is automatically generated by Android tools.
# Do not modify this file -- your changes will be erased!
#
# This file must be checked in version control systems.
#
# To customize properties used by the ant build system use,
# "Build. properties", and override values to adapt the script to your
# Project structure.
# Project target.
Target = Android-9
Proguard. Config = proguard. cfg
 

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!

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/Zengyangtech/archive/2011/01/10/6127600.aspx

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.