Android Proguard: androidproguard

Source: Internet
Author: User

Android Proguard: androidproguard

Generally, code encryption is required for commercial projects. Android provides a code obfuscation method, which is described as follows:

I. Introduction

1. Introduction

Obfuscators compress, optimize, and confuse code by deleting unused code and renaming classes, fields, and methods with obscure names. The result is a relatively small .apk file, which is difficult to reverse engineer. Therefore, obfuscators are an important protection tool when your applications are sensitive to security (high requirements), for example, when you authorize applications.

Obfuscators are integrated into android build systems, so you do not have to call them manually. At the same time, obfuscators run only when building applications in release mode, so you do not have to deal with obfuscation code when building a program in debug mode. It is optional for the obfuscator to run, but it is recommended.

2. Notes

When creating a project in the new adtfile, the mixed file is no longer proguard.example, but project.propertiesand proguard-project.txt.

If you need to perform global mixed code for the project, you only need to perform one operation:

In project. properties

'# Proguard. config =$ {sdk. dir}/tools/proguard/proguard-android.txt: proguard-project.txt' # 'to remove it.


If some Code cannot be confused, for example, if you need to add the so file and call the method in it, the method that calls JNI to access the so file cannot be mixed. During export, no error may be reported. However, when the so file needs to be called when running on the mobile phone, the system reports that the method cannot be found. In this case, proguard-project.txt is used.

2. Enable ProGuard in Eclipse

1. Check whether the proguard folder exists in the Android SDK directory.
For example, D: \ Environment \ android-sdk-windows \ tools \ proguard
2. Configuration
1. Check that the proguard.((or proguard-project.txt) file exists in the project root directory. If the file does not exist (indicating that the current project is a project earlier than 2.3), create a 2.3 android project and set proguard from the project. copy the cfg file to the root directory of your project without any changes (unless you understand how to customize your obfuscation Policy). Continue with the following steps.
2) If yes, find default in the root directory of the project. properties [if you are using ADT14 or a later version, there is no default in the project. properties file, only project. properties file, find the project. properties file] File, add a configuration in the file: proguard. config = proguard. cfg
This completes the configuration.

3. Syntax Rules

# Original android obfuscation template # optimized # executed by a specified number of optimizations #-optimizationpasses n # optimized-optimizationpasses 5 # optimized # classes that do not generate a variety of classes during obfuscation #-dontusemixedcaseclassnames # -------------------------------- #-dontusemixedcaseclassnames # ---------------------------------- # specify not to ignore non-public library classes #-dont Skipnonpubliclibraryclasses # lower #-dontskipnonpubliclibraryclasses # lower # No pre-check #-dontpreverify # lower # output generation information #-verbose # lower-verbose # optimized # optimizations {optimization_filter }# -----------------------------------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 >;}# ----------------- # modify modification merge # ------------------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 *;} # entity # Protection Type-Description of keepattributes # Exceptions, Signature, Deprecated, SourceFile, SourceDir, LineNumberTable, LocalVariableTable, # entity, Synthetic, EnclosingMethod, entity, entity, # RuntimeVisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations, and AnnotationDefault # -------------------keepattributes **-libraryjars <java. home>/lib/rt. jar # example # Do not compress the specified file #-dontshrink # ---------------------dontshrink # example # the specified file is not optimized #-dontoptimize # example # Do not confuse the specified file # -dontobfuscate # --------------------- obfuscation package path --------repackageclasses ''-flattenpackagehierarchy''-target 1.6 # -------- The following is the use of roboguice-1.1.2.jar and guice-2.0-no_app.jar functions to protect fields and class-related --------- keep class com. google. inject. binder-keepclassmembers class * {@ com. google. inject. inject <init> (...);} -keepclassmembers class * {void * (** On * Event);}-keepclassmembers class **. r$ * {public static <fields >;}# ------ the jar package required for compilation-libraryjars D: /dev_rc/android-sdk-windows/add-ons/addon_google_apis_google_inc_11/libs/maps. jar # ------ protect third-party jar packages of Google and interface special effects -----------keep class android. support. v4. **-dontwarn android. support. v4. ** # ------ protect Baidu address jar package ---------keep class com. baidu. mapapi. ** {*;}-dontwarn com. baidu. mapapi. ** # --- ignore the warning of the following classes during packaging ---dontwarn com. classpackage. AA #-keepnames class * implements java. io. serializable # --------- protect the field names in all entities -----------keepclassmembers class * implements java. io. serializable {<fields >;}# --------- all method names in the protection class -------------keepclassmembers class * {public <methods> ;}

Reference: http://huangyuan.iteye.com/blog/1472732

If you have any questions, please leave a message and repeat the source.


In android, what is the use of the proguardcfg file?

This is used for code obfuscation.
You can search for android code obfuscation to see how you configure this file.

Code obfuscation aims to prevent your apk from being decompiled and all the code is exposed. however, the current code obfuscation only changes the name. You can still find a way to restore the code During decompilation, so you cannot really confuse it.

I created a new android project in eclipse, and finally said that I lack proguardcfg. How can I solve this problem?

Update the sdk.

1. Eclipse --> Window --> Android SDK And AVD Manager

2. Select the SDK tools in installed packages and click update all ..

The problem can be solved in the preceding two steps.

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.