I'm publishing an Android application developed in Eclipse and, as stated in the title, I would like to integrate Proguard obfuscation into the build, specifically for exporting a signed app.
Anyone had any luck without going down the ant path?
I also wanted to do this without using Ant or the command line approach. Here is what worked (on Eclipse + Windows only):
(You need to download Proguard. The script expects to find it here: C:\android-sdk_r04-windows\proguard\lib\proguard.jar).
Create a Windows batch file, "C:\android-sdk_r04-windows\obfusc.bat":
DEL /S /Q obfuscated
MKDIR obfuscated
java -jar C:\android-sdk_r04-windows\proguard\lib\proguard.jar @android.pro
DEL /S /Q bin\com\
DEL /S /Q bin\org\
ROBOCOPY obfuscated\com bin\com /S
In Eclipse, bring up the properties page of your Android project, select the "Builders" pane and add a new builder of type "Program." In the "Location" field of the main tab put the absolute path of the script in the previous step. In the "Working directory" field put the variable ${build_project}. In the "Build options" tab select "After a clean" under "Run builder."
Make sure this build tool comes next to last, just before the Android package builder.
Create a proguard config file in the root folder of the Android project. I customize these slightly and include them in revision control, but that's up to you. The file I use is called "android.pro," as named in the script, and is similar to the config in the dev blog but includes a header with injar, outjar, and libraryjar statements, for example:
-injars bin(!.svn/**)
-outjars obfuscated
-libraryjars C:\android-sdk_r04-windows\android-sdk-windows\platforms\android-1.6\android.jar
-libraryjars C:\GoogleAnalyticsAndroid_0.7\libGoogleAnalytics.jar
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-printmapping proguard.map
-keepattributes SourceFile,LineNumberTable
-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 com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native ;
}
-keepclasseswithmembernames class * {
public (android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public (android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
I think that's about it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With