Proguard Customary method

Source: Internet
Author: User
Tags modifiers

Run Proguard, enter now (of course you need to navigate to the Proguard.jar directory below):
java-jar proguard.jar Options ...
Proguard.jar in the Lib directory (/tools/proguard can be found under Android SDK), and the bin directory has some Linux and Windows scripts that can execute this command. Typically, you can put the options in a file (say Myconfig.pro), that's all you need:
Java-jar Proguard.jar @myconfig. Pro
You can combine command-line options and configuration file options, such as:
Java-jar proguard.jar @myconfig. Pro-verbose
Add comments using #, you can comment out a line
The space between the text and the delimiter is ignored, and the file name contains spaces or special characters quoted in single or double quotation marks. An option can be any combination of parameters in the command line or a command line in a configuration file, such as: You can refer to any command-line Options section to avoid shell extensions for special characters.
The order of the options is usually irrelevant, and for brevity, you can replace them with their first unique letter.
input/output Options
Keep Options
Shrinking Options
optimization Options
Obfuscation Options
preverification Options
General Options
Class Paths
File Names
File Filters
Filters
Overview of Keep Options
Keep Option Modifiers
Class Specifications

Input/output Options

@filename is '-include filename ' shorthand

-include filename

Recursive read configuration options from a given file name

-basedirectory directoryname

Specify a directory for subsequent relative file names or these configuration files within these configuration parameters.

-injars Class_path

Specifies the jars (or wars, ears, zips, or directories) paths to be processed by the application, and the class files inside these jars are processed and written to the output jar. By default, all files that do not contain. Class will be copied by the original wind, please note any temporary files, especially if you import files directly from the directory. The entries in the class path are filtered out as described by filters. For better readability, you can use more than one of the specified Classpath entries-injars option.

-outjars Class_path

Specifies the name of the Jar,war,ear and directory to output after processing, and the previously-injars input file will be rewritten into the specified jar, which will allow you to select the input jar to the specified output jar. In addition, the output entries can be filtered out according to filters rules, and each processed class file and resource file is written to the input file of the first matching filter rule.
You must avoid having the output file rewritten in any of the input files. For better readability, you can use multiple Classpath entry-outjars options, and without any-outjars option, no jar will be overridden.

-libraryjars Class_path

Specifies the jar to which the program refers (such as the Rt.jar of the JDK) (or war, ears,zips, or directory). The files inside these jars are not entered into the output jar, and the specified library jars contains at least the application subclasses. The Library class files are only called without rendering, although their presence can improve the results of optimization, and these class paths are filtered by the filter's requirements. For better readability, you can use multiple Classpath entry-libraryjars options.
Please note that when looking for the library class, the boot path and Progurad run path are not taken into account, which means you have to explicitly indicate the Run-time jar your code will use. While this may seem cumbersome, it allows you to run your own programs in different runtime environments. For example, you can run J2SE applications and JME midlets by specifying the appropriate run-time jar.

-skipnonpubliclibraryclasses

In order to speed up the operation and reduce the use of proguard memory, when reading the library jars specifies to skip the Non-public class. By default Proguard reads the Non-public and public classes, however, if they do not affect the program code inside the input jar, the Non-public class is usually irrelevant. Ignore them to speed up the proguard without affecting the output. Unfortunately, some libraries, including the most recent JSE Run-time library, contain some of the non-public class libraries classes that inherit from the community, You can't use this option in this case. When using this option Proguard will print out a warning when the class is not found.

-dontskipnonpubliclibraryclasses

Specifies that the non-public library class is not ignored, which is the default setting above 4.5.

-dontskipnonpubliclibraryclassmembers

Specifies that library class members (fields and methods) that are visible to the package are not ignored. By default, Proguard will skip these class members when parsing the library class, and project classes will not generally refer to them. Sometimes, however, a class in a program is equivalent to a library class that exists in the same package. At this point they refer to the class members that their package is visible to. In this case it is useful to keep the program code consistent and to read members of these classes.

-keepdirectories [Directory_filter]

Specifies the directory to be saved in the output jars (or wars, ears, or directories). By default, the directory portion is removed, which reduces the size of the jar, but when the program tries to find them with the constructor, there will be an unseen result such as: "MyClass.class.getResource (" ")" If this option does not have a filter, all directories will be saved. , only directories that match the filter are saved when there is a filter.

-target version

Specifies the version number in the class file being processed. The version number can be 1.0,1.1,1.2,1.3,1.4,1.5 (or 5), 1.6 (or 6), 1.7 (or 7), and by default the version number of the class file remains unchanged. For example, you might want to update the class file to Java 6 by changing their version to pre-compile it.

-forceprocessing

Specifies the input process, even if the output looks up to date. This latest test is based on comparing the specified input, output, and configuration file or the timestamp of the directory.

Keep options-keep [, modifier,...] Class_specification

The protection of the specified object is not confused, and the specified class and class members (variables and methods) are saved as portals to the program. For example, to keep an application, you can specify the main class and its main method individually. In order to process the library, you should specify all exposed elements.
e.g:
-keep public class MyPackage. Mymain {
public static void Main (java.lang.string[]);
}

-keepclassmembers [, modifier,...] Class_specification

Specifies that class members that are not confused are better protected if their classes are also protected. For example, you want to protect variables and methods that can serialize classes.
-keepclassmembers class * Implements Java.io.Serializable {
private 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 ();
}

-keepclasseswithmembers [, modifier,...] Class_specification

Protects the members of the specified class and class, but the condition is that all specified classes and class members are to be present. For example, you want to keep a list of application that contain the main method without displaying them.
-keepclasseswithmembers public class * {
public static void Main (java.lang.string[]);
}

-keepnames class_specification

It's-keep,allowshrinking Class_specification's initials.
Protects the names of the members of the specified class and class (if they are not removed in the compression step)

Keepclassmembernames class_specification

Equivalent to-keepclassmembers,allowshrinking class_specification
Keep only member names, confuse content

Keepclasseswithmembernames class_specification

Equivalent to-keepclasseswithmembers,allowshrinking class_specification
If these specified classes exist after the compression phase, the names of the members of the specified class and class are protected.
Keep the native method from being confused:
-keepclasseswithmembernames class * {
Native <methods>;
}

-printseeds [FileName]

Lists the members of classes and classes that match the various-keep options, standard output to the given file.

Shrinking Options-dontshrink

The compression input class file, by default, is to be compressed, except that the class listed in-keep and the class files are directly or indirectly referenced between the files are removed, the compression step is performed after optimization, because optimizations may remove more class files and class members.

-printusage [FileName]

Specifies that the dead code in the input file is output to a standard file and is suitable for use with compression.

-whyareyoukeeping class_specification

Print out the reasons why these class files and class members were preserved during the compression process, as well as the use of compression.

Optimization Options-dontoptimize

Specifies that the input class file is not optimized, and the optimization function is turned on by default, and all methods are optimized at the byte level. 、

-optimizations Optimization_filter

Specifies whether optimizations are available or forbidden, this is a more granular option that is only applicable when optimized. This is a professional option.

-optimizationpasses N

Specifies the number of iterations to optimize the code, which in Android is 5 by default, and this instruction only works when it can be optimized.

-allowaccessmodification

Optimizations allow access to and modification of members of classes and classes with modifiers, which improves the results of the optimization step. For example, when a public getter method is inline, this may also require public access outside the field. Although the Java Binary specification does not require this, there is a problem with the virtual machine processing the code. Applicable when-repackageclasses is optimized and used.
directive: The code in the library cannot be processed with this instruction because some classes and class members are not designed to be public and may become public in the API

-mergeinterfacesaggressively

Specifies that the interface can be merged, even if the implementation class does not implement all methods. This option reduces the size of the output file by reducing the total number of classes. Available only when optimization is turned on.

Obfuscation options-dontobfuscate

Specifies that the class file is not obfuscated and is turned on by default.

-printmapping [FileName]

The mapping between the output class and the new old name of the class member is in the specified file. Available only when obfuscation is turned on.

-applymapping filename

Reusing mappings, classes and class members that are not listed in the mapping file use random names. If the code structure changes fundamentally, proguard may output mappings that can cause conflicting warnings. You can reduce the risk by adding the-useuniqueclassmembernames option. Only one mapping file can be specified. Available only when obfuscation is turned on.

-obfuscationdictionary filename

Use the keyword in the file as the name of the method and the field after it is confused. By default, a short name such as ' a ', ' B ' is used as the name of the confusion. You can specify a reserved keyword or an unrelated identifier. Spaces, punctuation marks, repeated words, and comments in the file are ignored. Available only when obfuscation is turned on.

-classobfuscationdictionary filename

Use the keyword in the file as the name that is confused with the class, similar to-obfuscationdictionary. Available only when obfuscation is turned on.

-packageobfuscationdictionary filename

Use the keyword in the file as the name after the package is confused, similar to-obfuscationdictionary. Available only when obfuscation is turned on.

-overloadaggressively

Turn on intrusive overloading obfuscation. Multiple fields and methods allow the same name, as long as their parameters and return value types are different. This option makes the processed code smaller (and harder to read). Available only when obfuscation is turned on.
Note: Dalvik cannot handle overloaded static fields

-useuniqueclassmembernames

The same name is confused with the same name, and the method has a different name after it is confused. When this option is not used, class members can be mapped to the same name. Therefore, this option increases the size of the output file slightly. Available only when obfuscation is turned on.

-dontusemixedcaseclassnames

Confusion does not result in mixed-case class names. The default confusing class name can contain uppercase and lowercase. If the jar is decompressed to a non-case sensitive system (such as Windows), the Unzip tool may overwrite another file with a similar name. Available only when obfuscation is turned on.

-keeppackagenames [Package_filter]

Does not confuse the specified package name. A filter is a comma-delimited list of package names. Package name can be included? ,, * wildcard characters, and can be added before the package name! Negative characters. Available only when obfuscation is turned on.

-flattenpackagehierarchy [Package_name]

RePack all the renamed packages into the given package. If no arguments or strings are empty, the package moves under the root package. This option is an example of further confusing package names, making the processed code smaller and harder to read. Available only when obfuscation is turned on.

-repackageclasses [Package_name]

RePack all renamed classes into the given package. If no arguments or strings are empty, the class's package is completely removed. This option overrides-flattenpackagehierarchy, another example of further confusing package names, which makes the processed code smaller and harder to read. Used to be named-defaultpackage. Available only when obfuscation is turned on.

-keepattributes [Attribute_filter]

Any optional attributes are reserved. A filter is a comma-delimited list of properties supported by the JVM and Proguard. Property names can be included? ,, * wildcard characters, and can be preceded by the attribute name! Negative characters. For example, the Exceptions,innerclasses,signature property should be added when working with library files. While preserving the SourceFile and Linenumbertable properties, you can still get accurate stack information after confusion. At the same time, you may retain the annotations property if your code has use annotations. Available only when obfuscation is turned on.

-keepparameternames

The name and type of the parameter that holds the reserved method. Available only when obfuscation is turned on.

-renamesourcefileattribute [string]

Specifies a constant string as the value of the sourcefile (and SourceDir) property. The reservation needs to be specified by the-keepattributes option. Available only when obfuscation is turned on.

-adaptclassstrings [Class_filter]

Confuse strings that are consistent with the full class name. When you do not specify a filter, all string constants that conform to the full class name of an existing class are confused. Available only when obfuscation is turned on.

-adaptresourcefilenames [File_filter]

Renames the specified source file as a sample with the Obfuscated class file. When no filter is specified, all source files are renamed. Available only when obfuscation is turned on.

-adaptresourcefilecontents [File_filter]

Confuses a class file as a sample to confuse the specified source file with the full class name in the same content. When no filter is specified, all content in the source file that is consistent with the full class name is confused. Available only when obfuscation is turned on.

Preverification options-dontpreverify

Specifies that the processed class file is not pre-validated. By default, if the target platform for a class file is Java Micro Edition or Java 6 or higher, it will be pre-checked. The target platform is Android when no need to turn on, off to reduce processing time.

-microedition

Specifies that the processed class file target platform is Java Micro Edition.

General Options-verbose

Specifies that more relevant information is printed during processing.

-dontnote [Class_filter]

Specifies that the information is not printed when a potential error or omission occurs in the configuration. This information may be useful when the class name is wrong or missing option. Class_filter is an optional regular expression. When the class name matches, Proguard does not output information about these classes.

-dontwarn [Class_filter]

Specifies that no warning messages are printed when references or other important issues are not found. Class_filter is an optional regular expression. When the class name matches, Proguard does not output information about these classes.
Note: If the referenced class or method is not found to be required during processing, the processed code will not function correctly. Use this option when you are clear about the impact of the operation.

-ignorewarnings

Print a warning message that no references or other important issues were found, but continue to process the code.
Note: If the referenced class or method is not found to be required during processing, the processed code will not function correctly. Use this option when you are clear about the impact of the operation.

-printconfiguration [FileName]

Outputs the resolved configuration criteria to the specified file. This option is available for debug configurations.

-dump [FileName]

The internal structure of the standard output class file is in the given file. For example, you might want to export the contents of a jar file without having to do any processing.

Proguard Customary method

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.