Obfuscating from Eclipse

Posted: August 28, 2010 in Android, Eclipse
Tags: , , , , ,

WARNING this is not for the faint-of-heart! It will break upon SDK revisions! Because it might result in more work for  GoogleOHA Engineers they might discourage it! WARNING, THIS ONLY WORKS WITH ECLIPSE! If you look at the SetUP Ant task code you will find that it checks for an sdk.ant.build.revision number with a max value of 3 set at this time. The value is stored in the sdk.properties file at the root of the platform version folder.

Now, here is the trick. Change the number to the max which is 3. DO NOT STOP YET AS YOU ARE NOT DONE. Copy the complete set of ant_rules_r2.xml, ant_libs_rules_r2.xml, etc and change the copy names to use r3.  Add the new obfuscate target making sure to add the other stuff such as Proguard config checking, etc. Now change that dex target by setting depends to include the obfuscate target you added after the compile target in that depends line.

Now, fire up Eclipse and compile all you want knowing that its being obfuscated automatically. Neat huh? FINAL WARNING, I HAVE NOT TESTED THIS WITH ANDROID LIBRARY PROJECTS YET!

I found it as I was looking at ways to decrease the ANT build script code I was writing and I really did not want to re-invent what Google/OHA were already doing with anttasks and android development tools. Its not the tools folks, despite what Joe Hewitt claims. Its the knowledge of hacking up the tools to do what you want!

Enhanced by Zemanta
Advertisements
Comments
  1. Christopher says:

    If you’re copying and renaming entire files from the Android SDK, changing them upon each upgrade cycle, you’re doing it wrong.

    The Android devs have made it super easy to override individual targets, or to provide additional parameters, via their use of macrodefs.

    All you have to do is take the basic Ant you’re given from `android create project` and then override the “-package-release” target if you want to inject a ProGuard step into your build.

    By override, I mean basically just copy into your project-local Ant file, so that you can change the “depends”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s