Use proguard to confuse Android source code

Source: Internet
Author: User

Use proguard to confuse Android source code

1. APK file obfuscation method

See:

Android: Develop/tools/proguard

Android 2.3 code obfuscation proguard Technology Introduction

2. obfuscation of jar packages

During the project, we will pack some public items into jar packages for the program to call. Through the decompilation tool, you can easily obtain the source code of our jar package. To prevent others from getting the fruits of our work, we can use proguard to confuse our jar packages.

Find the tools \ proguard \ bin folder in your android SDK directory. There are three files below. We find the proguardgui file, and we use it to confuse our jar packages.

First, double-click the proguardgui file and the following dialog box appears.

We compile our configuration items

Let's take a look at the android standard proguard. cfg (Android project automatically generated, path: <project_root>/proguard. cfg) Configuration item

-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 * 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);}-keepclassmembers enum * {    public static **[] values();    public static ** valueOf(java.lang.String);}-keep class * implements android.os.Parcelable {  public static final android.os.Parcelable$Creator *;}

Edit as follows:

-Injars test. jar # test. jar is the jar package to be obfuscated. You can enter the path. If no path exists, it is in the same directory as proguard by default-outjars test_out.jar # test_out.jar is the jar package you have obfuscated. You can enter the path, if no path exists, it is in the same directory as proguard-libraryjars libs \ Env. jar # libs \ Env. jar is a supported library package, there may be many (similar to the addition of a sentence in this statement), here we use a demo-optimizationpasses merge # Do not compress, sometimes it may be confusing if you do not set it.-ignorewarnings # ignore warnings. You can set it as needed. # here, only the two Configuration items, there are many configuration items, you can study-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 * extends android. app. backup. backupagenthelper-keep public class * extends android. preference. preference-keep class COM. test. openclass # assume that com. test. openclass is a class that we open to others to call. We will keep from being confused. Here is a demonstration-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);}-keepclassmembers Enum * {public static ** [] values (); public static ** valueof (Java. lang. string);}-keep class COM. test. * {Public <fields>; Public <Methods>; *** Set * (***); *** get * () ;}# here we keep COM. public fields and methods of all classes in the test package and set and get methods # more keep methods can be studied-keep class * implements android. OS. parcelable {public static final android. OS. parcelable $ creator *;}

Save the file as XX. pro, and then use load configuration

Import, and next until the end. If the operation fails, locate the error as prompted, modify the configuration information, and restart

The test was successful at a.m. on November 30!

References:

Step by step teach you how to use proguard to confuse Java source code

Proguard usage

Proguard User Guide

------------------------------------------------------------------ Update ------------------------------------------------------------------

1. About the-libraryjars ** option in the configuration file, I have been hesitant to add or not to add it at the beginning of my test. Today, a problem occurs. If this problem is not added, the following occurs:

Some@ OverrideThe method name is also obfuscated. In this way, some callback methods may not be found during execution, and errors may occur. Therefore, you need to add this method later.

2013-05-

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.