Android and ProGuard
How to set ProGuard to ANT script for Android
STEP #1
Create a build.xml for ANT
c:/> ant update project --path c:/my_src
Create a build.property for keystore
STEP #2
EDIT build.xml
STEP #3
SETS ProGuard
STEP #4
BUILD
STEP #5
TEST, that's it!
//
// build.property
//
#application-package=com.test.testApp
#sdk-location=C:/android/android-sdk-windows/platforms/android-6
# KeyStore/Alias
key.store=__MY_KEYSTORE__.keystore
key.alias=__MY_KETSTORE_ALIAS__
key.store.password=__PASSWORD__
key.alias.password=__PASSWORD__
//
// build.xml
//
// --------------------------------
// 1. replace <setup />
// --------------------------------
by
<!-- <setup /> -->
<setup import="false" />
// --------------------------------
// 2. Adds this in the below <setup import="false" />
// --------------------------------
<!-- ProGuard -->
<property name="proguard-dir" value="proguard"/>
<property name="unoptimized" value="${proguard-dir}/unoptimized.jar"/>
<property name="optimized" value="${proguard-dir}/optimized.jar"/>
<target name="optimize" unless="nooptimize">
<jar basedir="${out.classes.dir}" destfile="${unoptimized}"/>
<java jar="${proguard-dir}/proguard.jar" fork="true" failonerror="true">
<jvmarg value="-Dmaximum.inlined.code.length=16"/>
<arg value="@${proguard-dir}/config.txt"/>
<arg value="-injars ${unoptimized}"/>
<arg value="-outjars ${optimized}"/>
<!--<arg value="-libraryjars ${android.jar}"/>-->
<!-- ADDS Library -->
<arg value="-libraryjars ${android.jar}" />
<!-- <arg value="-libraryjars libs/xxx.jar; libs/yyy.jar"/> -->
<!-- ADDS Library -->
</java>
<!-- Delete source pre-optimized jar -->
<!--delete file="${unoptimized}"/-->
<!-- Unzip target optimization jar to original output, and delete optimized.jar -->
<delete dir="${out.classes.dir}"/>
<mkdir dir="${out.classes.dir}"/>
<unzip src="${proguard-dir}/optimized.jar" dest="${out.classes.dir}"/>
<!-- Delete optimized jar (now unzipped into bin directory) -->
<delete file="optimized.jar"/>
</target>
<!-- ProGuard -->
...
<!-- 3. Copy rule and paste into build.xml; see below -->
...
</project>
// --------------------------------
// 3. Copy rule and paste into build.xml
// --------------------------------
OPEN a rule xml file
<SDK_PATH>/platforms/<target_platform>/templates/android_rules.xml
COPY from in the below <project name="android_rules" default="debug">
to in the above </project>
then, PASTE this in the below ProGuard
// --------------------------------
// 4. Finds <target name="-dex" depends="compile">
// --------------------------------
then, adds ", optimize" beside "compile"
<!-- ProGuard -->
<target name="-dex" depends="compile, optimize">
<!-- ProGuard -->
...
//
// ProGuard
//
// --------------------------------
// 1. Get latest version
// --------------------------------
Download: http://sourceforge.net/project/showfiles.php?group_id=54750
// --------------------------------
// 2. Copy proguard.jar where into downloaded zip archive to my project directory
// --------------------------------
create a directory "proguard" into my project source directory
then, copy proguard/lib/proguard.jar to c:/my_src/proguard
// --------------------------------
// 3. Create a config.txt into "my_src_dir/proguard"
// --------------------------------
# --------------------------------------------------
# ProGuard:
# http://proguard.sourceforge.net/
# ProGuard Download:
# http://sourceforge.net/project/showfiles.php?group_id=54750
#
# config.txt Source:
# http://www.androidengineer.com/2010/07/optimizing-obfuscating-and-shrinking.html
# --------------------------------------------------
-target 1.6
-optimizationpasses 2
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
#-verbose
#-dump class_files.txt
#-printseeds seeds.txt
#-printusage unused.txt
#-printmapping mapping.txt
# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle.
-optimizations !code/simplification/arithmetic
-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 View {
#public <init>(android.content.Context);
#public <init>(android.content.Context, android.util.AttributeSet);
#public <init>(android.content.Context, android.util.AttributeSet, int);
#public void set*(...);
#}
# --------------------------------------------------
// --------------------------------
// build
// --------------------------------
c:/my_src> ant compile
c:/my_src> ant release
-----
Cheers,
June
수요일, 9월 15, 2010
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기