views:

152

answers:

2

I'm publishing an android application develpoed in eclpis 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?

+1  A: 

Ok, this is the most relevant and recent post on the topic:

http://android-developers.blogspot.com/2010/09/proguard-android-and-licensing-server.html

It dose use Ant, but all the hard parts are done for you, and as long as you follow the instruction, it works. A note: don't skip the update this only work with SDK r7+, and it's not a bad idea to run eclipse's update, for the AVD update too.

And, for anyone adding external jars, setup ProGuards procfg.txt and add:

-libraryjars {path}{file_name}.jar

rndStr
A: 

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);
    }
  • You will want to keep this Builder turned off most of the time. When it is time to test or export an obfuscated APK, turn it on and then do a "Project > Clean" from Eclipse, including the project and any library projects it depends on.

I think that's about it.

x-code