Powerful obfuscator proguard

Source: Internet
Author: User

Proguard is a cool obfuscator and shrinking tool (shrinker, please let me know if you have a better translation method ). In addition to obfuscation and protection of your code, it can also automatically detect and delete unused classes, methods, and data members, and remove the package hierarchy, minimize your jar package.
Another notable significance of using proguard is that it can automatically delete unused parts, so you can safely use module-Level Reuse instead of Code-Level Reuse adopted by usually j2ers, greatly improve development efficiency. Therefore, we solemnly recommend proguard to all j2s developers.
However, one problem is that proguard cannot be integrated into development environments such as JB and wtk (but it comes with wtk2.0). Instead, you must write your own command lines to use it, I think this is the biggest obstacle that restricts the use of proguard.
So I recently studied and wrote a script with a high degree of automation for you to use.
This script automatically performs everything for you: compilation, pre-packaging, obfuscation, pre-audit, packaging, and JAD file creation. In addition, an error in any step can be automatically stopped. I will first use JB for development, and use this script to process it before the final release.


For each new project, all the variables to be modified are concentrated in the variable setting section at the beginning of a. The seven variables are respectively the program name (the jar and Jad names will be used) main Class Name (MIDlet subclass), icon file name, compilation list (written in order of dependency), Java library path, proguard path, and author information. If you do not need the icon, You can omit or leave it blank (set icon_name =), while progard_home and app_vendor do not need to be modified repeatedly.
All resource files must be stored in the SRC res directory. This is my personal habit. You can change the script according to your habits.
========================================================== ==========================================
@ Echo off


Rem ####################################### #####################################
Rem # script for compiling, obfuscating, preverifying & packaging ##
Rem ####################################### #####################################


Setlocal


Rem ####################################### #####################################
Rem # Set up varialbles ##
Rem ####################################### #####################################
Set app_name = mygame
Set midlet_class = mygamemid
Set icon_namepolicicon.png
Set compile_list = src/COM/joyamigo/gamefast /*. java src/COM/joyamigo/util /*. java src/COM/joyamigo/gameui /*. java src /*. java
Set lib_path = C:/Nokia/devices/nokia_series_60_midp_concept_sdk_beta_0_2/lib/classes.zip
Set proguard_home = C:/jbuilder7/proguard1.6.2/
Set app_vendor = cnjm

Echo start building % app_name %
Echo.


Rem pause
Rem ####################################### #####################################
Rem # compiling ##
Rem ####################################### #####################################
Set step = compiling
Echo % step %...
If exist tmp1 RD/S/Q tmp1
MD tmp1
Javac-D tmp1-bootclasspath "% lib_path %"-classpath tmp1 % compile_list %
If errorlevel 1 goto Error
Xcopy/I/e src/RES tmp1/RES> NUL


Rem pause
Rem ####################################### #####################################
Rem # pre-packaging ##
Rem ####################################### #####################################
Set step = pre-packaging
Echo % step %...
Rem create manifest File
Echo manifest-version: 1.0> manifest. MF
Echo MIDlet-Name: % app_name %> manifest. MF
Echo MIDlet-1: % app_name %, % midlet_class %> manifest. MF
If not ''% icon_name %'' = ''' echo MIDlet-icon:/RES/% icon_name %> manifest. MF
Echo MIDlet-version: 1.0> manifest. MF
Echo MIDlet-vendor: % app_vendor %> manifest. MF
Echo microedition-configuration: CLDC-1.0> manifest. MF
Echo microedition-profile: MIDP-1.0> manifest. MF
Jar CFM tmp1.jar manifest. mf-C tmp1.
If errorlevel 1 goto Error
Del manifest. MF
RD/S/Q tmp1


Rem pause
Rem ####################################### #####################################
Rem # obfuscating ##
Rem ####################################### #####################################
Set step = obfuscating
Echo % step %...
Rem create proguard obfuscating script
Echo-libraryjars % lib_path %> myconfig. Pro
Echo-injars tmp1.jar> myconfig. Pro
Echo-outjar tmp1/tmp1.jar> myconfig. Pro
Echo-overloadaggressively> myconfig. Pro
Echo-dontusemixedcaseclassnames> myconfig. Pro
Echo-defaultpackage '''> myconfig. Pro
Echo-printseeds> myconfig. Pro
Echo-keep public class * extends javax. microedition. MIDlet. MIDlet> myconfig. Pro
MD tmp1
Java-jar "% proguard_home % lib/proguard. Jar" @ myconfig. Pro> NUL
If errorlevel 1 goto Error
Del tmp1.jar
Del myconfig. Pro


Rem pause
Rem ####################################### #####################################
Rem # preverifying ##
Rem ####################################### #####################################
Set step = preverifying
Echo % step %...
CD tmp1
Jar XF tmp1.jar
Del tmp1.jar
Preverify-classpath "% lib_path %"-D ..
If errorlevel 1 goto Error


Rem pause
Rem ####################################### #####################################
Rem # packaging ##
Rem ####################################### #####################################
Set step = Packaging
Echo % step %...
If exist ../% app_name %. Jar del ../% app_name %. Jar
Jar CFM ../% app_name %. Jar meta-INF/manifest. MF.
If errorlevel 1 goto Error
CD ..
RD/S/Q tmp1


Rem pause
Rem ####################################### #####################################
Rem # creating descriptor ##
Rem ####################################### #####################################
Set step = creating Descriptor
Echo % step %...
Rem create temporary batch to create JAD file
Echo MIDlet-1: % ~ N1, % 2 ^> % ~ N1.jad> tmp1.bat
If not ''% icon_name %'' = ''' Echo MIDlet-icon:/RES/% icon_name % ^> % ~ N1.jad> tmp1.bat
Echo MIDlet-jar-size: % ~ Z1 ^> % ~ N1.jad> tmp1.bat
Echo MIDlet-jar-URL: % 1 ^> % ~ N1.jad> tmp1.bat
Echo MIDlet-Name: % ~ N1 ^> % ~ N1.jad> tmp1.bat
Echo MIDlet-vendor: % 3 ^> % ~ N1.jad> tmp1.bat
Echo MIDlet-version: 1.0 ^> % ~ N1.jad> tmp1.bat
Call tmp1.bat % app_name %. Jar % midlet_class % app_vendor %
Del tmp1.bat


Echo.
Echo % app_name %. jar and % app_name %. Jad created, building completed.
Goto exit


: Error
Echo.
Echo error occurred while % step %, building stopped.
: Exit
Endlocal

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.