Android Obfuscation Pack

Source: Internet
Author: User
Tags object serialization

Before this, looked at the next Proguard official website introduction, and searched the relevant information.


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. When the integrated ADT now creates a new Android project, there will be a proguard-project.txt under the root path of the project directory. In fact, this file is the same as proguard.cfg. Some of the configurations for confusing packaging are written in this file.

Search the next Proguard confusion packaging related information, search to search all said are the same, as long as understand the basic use of methods, which confusion, which is not confused, the most common is to filter out some Android need to register some components are not confused, third party package does not need to be confused, Because some third-party packages have been confused, roughly in accordance with their needs to confuse the need to write a basic configuration on the line. Here I have made a basic synthesis, proguard configuration as follows:

-optimizationpasses 7- 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 Androi D.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 Com.android.vending.licensing.ilicensingservice-keepclasseswithmembernames class * {native <methods>;} -keepclasseswithmembers class * {public <init> (Android.content.Context, android.util.AttributeSet);} -keepclasseswithmembers class * {public <init> (Android.content.Context, android.util.AttributeSet, int);} -keepclassmembers class * extends android.app.Activity {public void * (aNdroid.view.View);}    -keep public class * extends Android.view.View {public <init> (android.content.Context);    Public <init> (Android.content.Context, Android.util.AttributeSet);    Public <init> (Android.content.Context, Android.util.AttributeSet, int.); public void set* (...);}    -keepclassmembers enum * {public static **[] values (); public static * * VALUEOF (java.lang.String);} -keep class * Implements android.os.Parcelable {public static final Android.os.parcelable$creator *;} -keepnames class * Implements Java.io.serializable-keepclassmembers class * Implements java.io.Serializable {static fi    NAL long Serialversionuid;    private static final java.io.objectstreamfield[] Serialpersistentfields;    !static!transient <fields>;    private void WriteObject (Java.io.ObjectOutputStream);    private void ReadObject (Java.io.ObjectInputStream);    Java.lang.Object Writereplace (); Java.lang.Object readresolve ();} -keepattributes signature-keepattributes *aNnotation*-keep class * *. r$* {*;}  -libraryjars Libs/android-support-v4.jar-dontwarn android.support.v4.**-keep class android.support.v4.** {*;} -keep interface android.support.v4.** {*;} -keep public class * Extends android.support.v4.**-keep public class * extends Android.app.Fragment


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 enumerated types, inherited parcelable cross-process data classes, and implementation serializable object serialization.

If there are other third-party packages, you can add without confusing the configuration on the line. According to the requirements, go to personality configuration Proguard confused on the line.


Finally remember to put the root directory path under the Project.Properties file:

# This file was automatically generated by Android tools.# does not modify this file--YOUR changes would be erased!## this F Ile must is checked in Version Control systems.## to customize properties used by the Ant build system edit# "Ant.properti  Es ", 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-17


Proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

The red note (minus the "#") opens at the bottom, so you can sign up and pack the APK.




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.