Java File Compression optimization tool (Proguard) software introduction Soft content

Source: Internet
Author: User

Proguard is a free Java class file compression, optimization, mixing device. It can help you remove useless classes, fields, methods, and properties, maximize bytecode optimization, and rename classes, fields, and methods with a short, meaningless name. Now that Eclipse has integrated Proguard, you can download the software if you need to use proguard alone.

How to use

1, prepare your jar package, I am here for example called Test.jar.

2, decompression Proguard, execute the bin directory proguardgui.bat.

3, run, click on the Left "Input/output" menu

4. Click "Add Input" on the right to add the jar package we want to mix, Test.jar

Click "Add Output" on the right to fill in the jar package we want to output (name whatever), here I write Test_out.jar.

Note the output of the jar package, to be completed by hand.

5, add support library, the bottom of the "library jars,wars,ears ..." That box. Click "Add" on the right.

To illustrate, it is best to copy the jar packages of all libraries in Java project in your myeclipse to a directory, and then add these jar packages here, MyEclipse's environment support jar package generally

6, after completing the above steps, should be like 4, so it is almost

7, click "Shrinking", set to 5. (can be set as needed, this is just my configuration)

8, click "Obfuscation", set 6. (can be set as needed, this is just my configuration)

9. Click "Optimization" to set 7. (can be set as needed, this is just my configuration)

10, click "Process", then click "Save Configuration", in the Popup dialog box, enter the name of the profile to be saved (here I am test.pro), and finally click "Save". 8

To some of the graphical setup sections have been completed.

11. Finally, add the classes and methods you want to keep.

Use the editor to edit the "Test.pro" just saved, with Notepad can be anything, open after the general should be the following look

-injars Test.jar
-outjars Test_out.jar

-libraryjars ' C:\Program Files (x86) \java\jdk1.6.0_10\jre\lib\rt.jar '
-libraryjars Lib\ant.jar
-libraryjars Lib\aopalliance-1.0.jar
-libraryjars Lib\commons-dbcp-1.4.jar
-libraryjars Lib\commons-fileupload-1.2.1.jar
-libraryjars Lib\commons-io-1.4.jar

..... Set the support library package, slightly

-dontskipnonpubliclibraryclassmembers
-dontshrink
-useuniqueclassmembernames
-keeppackagenames
-keepattributes exceptions,innerclasses,signature,deprecated,sourcefile,linenumbertable,localvariable*table,* Annotation*,synthetic,enclosingmethod
-keepparameternames
-ignorewarnings

.... Here we add the classes and methods that we want to keep, as follows, and the red ones we add.

-keep class Org.bl.soa.components.constant.* {
public;
public;
set* (* * *);
Get* ();

}

-keep class Org.bl.hibernate.* {
public;
public;
set* (* * *);
Get* ();
}

--antyi Modify 20150504 method is not confusing (note that the name of the package is written in full Android.content.Context):

-keepclasseswithmembers public class *com.typlugin.api.actions {
public static void Start (android.content.context,java.lang.string);
}

..... Continue to add other classes and methods to keep, and how much to write. I'm adding all the classes in Test.jar.

.... There are also some auto-generated configurations behind them.

.... Slightly

12, after writing, save.

Reopen the Progrard and execute the Proguardgui.bat in the bin directory.

Click the first option "Proguard", then click "Load Configuration" and select the "Test.pro" we just saved to load.

13, start to Mix code, click on the right "process", and then click "Process!", such as

14, waiting for the completion of processing, the output of the "Test_out.jar", is a mixed jar package, you can use the Xjad anti-editing to see the effect.

15, if there is a problem in the process, there will generally be a hint, most of the general is missing association classes, if less relevant classes, in the 7th step of the diagram, the lack of support package added to it.

Use note

1, note the version, if not the project needs, it is best to use the latest stable version, so that the chance of error, learning curve will be significantly shortened.

2, the best source of the same version of the JVM to start Proguardgui.jar, do not directly open with the default JVM.

3. Note that the Libraryjar included in the default load of Proguaardgui after startup is the same version as the version of the JVM that you used in the Rt.jar.

4, when using the 1.4 JVM to open Proguard, note in the Optimization tab, do not check the Keep enumerations option, Because Ching this option causes the Java.lang.Enum to appear in the Configration file, this class is only available in a 1.5 environment. The error message is as follows:

[Proguard] Note:the configuration refers to the unknown class ' Java.lang.Enum '
[Proguard] Note:there were 1 references to unknown classes.
[Proguard] You should check your the configuration for typos.

5. When embedding an ant script, there is usually a




Task.properties in Proguard.jar, reserved, Config.pro is the Proguard configuration file, preferably using Mr. Proguardgui.jar, and then manually modified as required.

Problems

1. Conversion to Dalvik format failed with error 1

There are several solutions on the Internet:

1. Edit the. classpath file under the Eclipse project, instead

Can

2, download the latest version of Proguard, replace the Android SDK under the Tools\proguard (I use this method to solve, my Android SDK is R20, with the Proguard is 4.7, I update it to 4.8 after the good)

3. Replace call%java_exe%-jar "%proguard_home%" \lib\proguard.jar%x in the Tools\proguard\bin\proguard.bat file with:
Call%java_exe%-jar "%proguard_home%" \lib\proguard.jar%1%2%3%4%5%6%7%8%9 (I tried it this way, but it led to another mistake. "Expecting class Path separator '; ' before ... in argument number 7 ")

Java File Compression optimization tool (Proguard) software introduction Soft content

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.