Android Java Obfuscation (proguard)

Source: Internet
Author: User

This article reproduced others blog, reproduced please indicate the source: http://www.blogjava.net/zh-weir/archive/2011/07/12/354190.html Proguard Introduction

Proguard is a very well-known open source project on SourceForge. Website website is: http://proguard.sourceforge.net/.

Java bytecode is generally very easy to decompile. In order to protect the Java source code very well, we often confuse the compiled class file. The main function of Proguard is to confuse. Of course, it can also reduce the size of bytecode, optimization, and so on, but those for us is a secondary function.

A quote from the official Proguard is:

Proguard is a free Java class file Shrinker, Optimizer, Obfuscator, and Preverifier. IT detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using a short meaningless names. Finally, it preverifies the processed code for Java 6 or for Java Micro Edition.


Android Eclipse Development Environment and Proguard

Before Android 2.3, it was very inconvenient to confuse Android code by manually adding Proguard for code obfuscation. After 2.3, Google has added this tool to the SDK's toolset. Specific path: Sdk\tools\proguard. When you create a new Android project, a proguard configuration file proguard.cfg appears under the root path of the project directory. In other words, we can use the simple configuration to confuse Android engineering directly with Proguard in our Elipse project.

The exact steps to confuse are very simple. First, we need to add a sentence in the project description file Default.properties to enable Proguard. As shown below:

1-optimizationpasses 5
2-dontusemixedcaseclassnames
3-dontskipnonpubliclibraryclasses
4-dontpreverify
5-verbose
6-optimizations!code/simplification/arithmetic,!field/*,!class/merging/*
7-keep public class * extends Android.app.Activity
8-keep public class * extends Android.app.Application
9-keep public class * extends Android.app.Service
10-keep public class * extends Android.content.BroadcastReceiver
11-keep public class * extends Android.content.ContentProvider
12-keep public class * extends Android.app.backup.BackupAgentHelper
13-keep public class * extends Android.preference.Preference
14-keep public class Com.android.vending.licensing.ILicensingService
15
16-keepclasseswithmembernames class * {
Native <methods>;
18}
19
20-keepclasseswithmembernames class * {
Public <init> (Android.content.Context, Android.util.AttributeSet);
22}
23
24-keepclasseswithmembernames class * {
Public <init> (Android.content.Context, Android.util.AttributeSet, int.);
26}
27
28-keepclassmembers enum * {
public static **[] values ();
public static * * VALUEOF (java.lang.String);
31}
32
33-keep class * Implements Android.os.Parcelable {
public static final Android.os.parcelable$creator *;
35}
36


It retains the main inheritance from activity, application, Service, Broadcastreceiver, ContentProvider, Backupagenthelper, Subclasses of preference and Ilicensingservice. Because these subclasses can be called externally.

In addition, it retains classes that contain the native method, constructors that are constructed from XML (typically a subclass of view), values and valueof static methods in enumeration types, and cross-process data classes that inherit parcelable.

In a real project, it is possible that Google's auto-generated configuration is not up to our confusing work. So, we often need to write some proguard configuration ourselves. This information is described in detail in the usage manual-I of the official website. We can look into it.


Resources

"Proguard official"

"Android 2.3 Code obfuscation Proguard Technology Introduction"

Reprint Please specify the Source: http://www.blogjava.net/zh-weir/archive/2011/07/12/354190.html

Android Java Obfuscation (proguard)

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.