jcpalmer
|
Posted: May 28, 2009 23:35 by jcpalmer
|
|
In a long ago thread, I talked about getting an optimizer/obfuscator, Proguard, into the build process. I have been successful. Given that the Android external tools - Netbeans Free Form Project route works well with 1.5, I made an xml import file to reference. Directions for install are in the file itself. I tried to use existing ant properties for locations of things, like android.jar, for low maintenance. I works for me on 1.1. I have not tested on 1.5 yet, but am hopeful it will work for both. Feel free to test it out for yourself. FYI, the 'proguard-release' target can used to generate a signed debug APK, by changing signed="true", if that helps your testing of this. Enjoy. File:========================================================= <?xml version="1.0" encoding="UTF-8"?> <!-- This file is intended to be used with an Android External Tools created project, & surrounded by a Netbean's Free Form Project. If you do not already have Proguard download it from: http://proguard.sourceforge.net . If you did not put it in 'c:/proguard4.3', then you must edit the taskdef at the beginning of the Proguard section. This file attempts to be general enough, so that you do not need to have one per project, sort of a poor man's plug-in. You can save this file where you want, like the android sdk dir. An import tag needs to be added, to use it. This can be in the build.xml of each project, or the android_rules.xml in each platforms templates sub-directory. Syntax: <import file="c:/android-sdk-windows-1.5_r1/netbeans-proguard-import.xml"/> The final target, proguard-release, produces an un-signed .apk, from compiled source & libs directory jars. You will need ant installed. To produce APK, change to projects root dir & type "ant proguard-release". --> <project name="netbeans-proguard-import"> <!-- ======================= NETBEANS SECTION ========================= --> <!-- map targets to the names netbeans uses --> <target name="build" depends="debug" /> <target name="install-it" depends="install" /> <target name="reinstall-it" depends="reinstall"/> <!-- TO DO: See if Android debugging tool, DDMS, can be integrated with Netbeans. Netbeans help topic: Creating A Debug Target for a Free-Form Java Project Android doc page: file:///C:/android-sdk-windows-1.5_r1/docs/guide/developing/tools/ddms.html --> <!-- ======================= PROGUARD SECTION ========================= --> <taskdef resource="proguard/ant/task.properties" classpath="c:/proguard4.3/lib/proguard.jar"/> <property name="proguard-out-jar" value="${out-folder}/${ant.project.name}-proguard-out.jar"/> <!-- Obfuscate the classes prior to dexing. Classes output include those from the libs directory, which is VERY important. Libraries are the most likely places to find classes / methods that never end up getting used. This does cause changes in the dex & release targets, copied from android_rules.xml. Dex target also changed to accept the output jar of this traget. --> <target name="obfuscate" depends="compile"> <proguard> -injars ${out-classes} -injars ${external-libs-folder} -outjars ${proguard-out-jar} -libraryjars ${android-jar} -keepclasses public class * extends android.app.Activity <!-- jam everything that is not an activity down to 1 package --> -repackageclasses _ <!-- -overloadaggressively DO NOT USE: VerifyError Exception --> -printseeds -printmapping ${ant.project.name}-mapping.txt -printusage ${ant.project.name}-deadcode.txt -verbose </proguard> </target> <!-- Convert proguard's jar into .dex files. Copied from android_rules.xml's "dex" target. changes: - compile dependency changed to obfuscate. - path arg commented out. - fileset commented out. - path datatype added specifying proguard's output jar. --> <target name="proguard-dex" depends="obfuscate"> <echo>Converting compiled files and external libraries into ${out-folder}/${dex-file}...</echo> <apply executable="${dx}" failonerror="true" parallel="true"> <arg value="--dex" /> <arg value="--output=${intermediate-dex-location}" /> <!-- <arg path="${out-classes-location}" /> --> <!-- <fileset dir="${external-libs-folder}" includes="*.jar"/> --> <path location="${proguard-out-jar}" /> </apply> </target> <!-- Package the application after running it through Proguard. Copied from android_rules.xml's "release" target. changes: - dex dependency changed to proguard-dex. - sourceFolder commented out. Source is LAST thing wanted in apk. - jarFolder commented out, since obfuscate target already handled. --> <target name="proguard-release" depends="proguard-dex, package-resources"> <apkbuilder outfolder="${out-folder}" basename="${ant.project.name}" signed="false" verbose="false"> <file path="${intermediate-dex}" /> <!-- <sourcefolder path="${source-folder}" /> --> <!-- <jarfolder path="${external-libs-folder}" /> --> <nativefolder path="${native-libs-folder}" /> </apkbuilder> <echo>All generated packages need to be signed with jarsigner before they are published.</echo> </target> </project> |
netbeans-proguard-import.xml
Replies: 1 - Last Post: July 28, 2010 23:11
by: sblantipodi
by: sblantipodi
showing 1 - 2 of 2
sblantipodi
|
Posted: July 28, 2010 23:11 by sblantipodi
|
|
it doesn't work for me... is there an update xml file that help us creating obfuscated file? |
Replies: 1 - Last Post: July 28, 2010 23:11
by: sblantipodi
by: sblantipodi






