# To enable ProGuard in your project, edit project. properties
# To define the proguard. config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# In $ {sdk. dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# Include property in project. properties.
#
# For more details, see
# Http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# And specify the fully qualified class name to the JavaScript interface
# Class:
#-Keepclassmembers class fqcn. of. javascript. interface. for. webview {
# Public *;
#}
# Jar packages to be obfuscated
-Injars androidtest. jar
# Jar package path output after Obfuscation
-Outjars out
# Jar packages dependent on the jar packages to be obfuscated
-Libraryjars/Users/tustar/Documents/Android/ADT/sdk/platforms/android-19/android. jar
-Optimizationpasses 5
# Classes with different names are not generated during obfuscation.
-Dontusemixedcaseclassnames
# Specify not to ignore non-public library classes
-Dontskipnonpubliclibraryclasses
# No pre-check
-Dontpreverify
-Verbose
# Optimization
-Optimizations! Code/simplification/arithmetic ,! Field /*,! Class/merging /*
# Retains subclasses inherited from Activity, Application, Service, BroadcastReceiver, ContentProvider, BackupAgentHelper, Preference, and ILicensingService. These subclasses may be called externally.
-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
# If JavaScript code is called in webview, keep it unchanged
-Keepclassmembers class fqcn. of. javascript. interface. for. webview {
Public *;
}
-Keep public abstract interface com. asqw. android. Listener {
# Do not confuse all methods
Public protected ;
}
-Keep public class com. asqw. android {
# Do not confuse this method
Public void start (java. lang. String );
}
# Reserved classes containing native Methods
-Keepclasseswithmembernames class *{
Native ;
}
# Retain the class constructed by the constructor from xml (generally a subclass of View)
-Keepclasseswithmembernames class *{
Public (Android. content. Context, android. util. AttributeSet );
}
# Retain the class constructed by the constructor from xml (generally a subclass of View)
-Keepclasseswithmembernames class *{
Public (Android. content. Context, android. util. AttributeSet, int );
}
# Protect members of a specified class. If this class is protected, it will be better protected.
-Keepclassmembers class * extends android. app. Activity {
Public void * (android. view. View );
}
# Keep the values and valueOf static methods in the enumeration type
-Keepclassmembers enum *{
Public static ** [] values ();
Public static ** valueOf (java. lang. String );
}
# Preserve the cross-process data class that inherits Parcelable
-Keep class * implements android. OS. Parcelable {
Public static final android. OS. Parcelable $ Creator *;
}
Role of ProGuard:
1. Create compact code documentation for faster network transmission, fast loading, and smaller memory usage.
2. It is difficult to use reverse engineering to create programs and libraries.
3. Therefore, it can delete code not called from the source file.
4. Make full use of the advantages of rapid loading of Java 6 to detect and return class files in Java 6 in advance.
Parameters:
-Include {filename}: Read the configuration parameters from the specified file.
-Basedirectory {directoryname}: Specify the base directory as the file name.
-Injars {class_path} specifies the application jar, war, ear, and directory to be processed.
-Outjars {class_path} specifies the name of the jar, war, ear, and directory to be output after processing.
-Libraryjars {classpath} specifies the application jar, war, ear, and library files required by the Directory to be processed.
-Dontskipnonpubliclibraryclasses specifies that non-public library classes are not ignored.
-Dontskipnonpubliclibraryclassmembers specifies that the visible Library Class Members of the package are not ignored.
Retain option
-Keep {Modifier} {class_specification} protects specified class files and Class Members
-Keepclassmembers {modifier} {class_specification} protects the members of the specified class. If this class is protected, it will be better protected.
-Keepclasseswithmembers {class_specification} protects the specified class and class members, but the condition is that all specified classes and Class Members must exist.
-Keepnames {class_specification} protects the names of members of the specified class and class (if they are not compressed and deleted in the step)
-Keepclassmembernames {class_specification} protects the names of members of the specified class (if they are not removed from the compression step)
-Keepclasseswithmembernames {class_specification} protects the names of specified classes and Class Members. If all specified class members are present (after the compression step)
-Printseeds {filename} lists the Member-keep options of classes and classes, and outputs them to the specified files.
Compression
-Dontshrink does not compress input class files
-Printusage {filename}
-Whyareyoukeeping {class_specification}
Optimization
-Dontoptimize: the input class file is not optimized.
-Assumenosideeffects {class_specification}: the specified method is assumed during optimization without any side effects.
-Allowaccessmodification: allows access to and modification of modifier classes and class members during optimization.
Obfuscation
-Dontobfuscate does not confuse input class files
-Printmapping {filename}
-Added obfuscation when applymapping {filename} is reused.
-Obfuscationdictionary {filename} uses the keyword in the given file as the name of the method to be confused
-Overloadaggressively: Application intrusive overload during Obfuscation
-Useuniqueclassmembernames: Determine the names of members of a unified obfuscation class to add obfuscation.
-Flattenpackagehierarchy {package_name} repacks all renamed packages and stores them in a given single package.
-Repackageclass {package_name} repacks all renamed class files and stores them in a given single package.
-Dontusemixedcaseclassnames does not produce a variety of class names when obfuscation is performed.
-Keepattributes {attribute_name,...} protects specified optional attributes, such as LineNumberTable, LocalVariableTable, SourceFile, Deprecated, Synthetic, Signature, and InnerClasses.
-Renamesourcefileattribute {string}: Set the given string constant in the source file.
Ant Example:
Classpath = "lib/proguard. jar"/>
-Injars in. jar
-Outjars out. jar
-Libraryjars $ {java. home}/lib/rt. jar
-Printmapping out. map
-Renamesourcefileattribute SourceFile
-Keepattributes SourceFile, LineNumberTable
-Keepattributes * Annotation *
-Keepclasseswithmembers public class *{
Public static void main (java. lang. String []);
}
-Keepclasseswithmembernames class *{
Native & lt; methods & gt ;;
}
-Keepclassmembers class * extends java. lang. Enum {
Public static ** [] values ();
Public static ** valueOf (java. lang. String );
}
-Keepclassmembers class * implements java. io. Serializable {
Static final long serialVersionUID;
Static final java. io. ObjectStreamField [] serialPersistentFields;
Private void writeObject (java. io. ObjectOutputStream );
Private void readObject (java. io. ObjectInputStream );
Java. lang. Object writeReplace ();
Java. lang. Object readResolve ();
}
After the obfuscator is run, the output files are:
Dump.txt
The internal structure of all class files in the pai.apk package.
Mapping.txt
Lists the mappings between source code and obfuscated classes, methods, and attribute names. This file is useful for bug reports after construction, because it translates obfuscated stack trace information into classes, methods, and member names in the source code. For more information, view the decoded stack trace information.
Seeds.txt
List unobfuscated classes and members.
Usage.txt
Extract the code from .apk.
Every time after the upload, dump.txt?mapping.txt mongoseeds.txt mongousage.txt is saved. mapping.txt must be saved, because the loss of this file will lead to the failure to find the source of the BUG.