Obfuscate Android apps?

I'm loving IDEA since I moved from Eclipse, a horrible piece of software (at least on Windows). I notice the next version of ADT will support Proguard directly, so the release build of the app has the debuggable flag set to false automatically AND the app can be obfuscated as part of the standard release process, that's a really great pair of time-savers.

Is there any way with IDEA 10 to implement Proguard obfuscation, or similar? Ideally I'd like to do it without creating an ANT script as I've no experience with ANT, and I'm just duplicating the perfectly good build process in IDEA.

I did try installing two plugins that pupport to support Proguard and yGuard, but although they show as installed, neither shows on the Facets/Modules menu, so I've no idea how to actually use them in my project, they just don't seem to work, but maybe I'm missing a configuration step.

Comment actions Permalink

Ideally I'd like to do it without creating an ANT script as I've no experience with ANT, and I'm just duplicating the perfectly good build process in IDEA.

Nevertheless I suggest to give ANT, the quasi-standard build tool of Java, a
try. It will help you for much more Java build and distribution tasks than
obfuscating/shrinking. It also has the advantage that you can build it
without the need of an IDE, e.g. a build server.


Comment actions Permalink

I'm sure I can get to grips with ANT, but given the choice between spending time creating a parallel build process (which I don't have any need for, I'm a sole developer) and continuing to work on the app, it's better to work on the latter.

The easier the tools are to use the more time can go into the apps, where it belongs.

Comment actions Permalink

There are tasks which should be done by the IDE and some which shouldn't.
Building a distributable package IMHO belongs in the second category.

There are dozens of obfuscators - why IDEA should support your preferred
one? Because Eclipse does? Sorry, this is no argument.


Comment actions Permalink

I'm happy to use any obfuscator, but as far as I can see IDEA doesn't include one suitable for Android and I cannot get a plugin to work. The only reason I'd use ANT is to implement an obfuscator, and that's not a particularly good justification for the work involved if there's a way to do it in the IDE.

Comment actions Permalink

One-click deployment is a time saver for all projects, even if it is an investment in the beginning:

  • compiling, obfuscating, packaging runs at the maximum speed that your machine is capable. Doing it manually takes plenty of extra time. Building is coffee, cigarette, or dzone.com break depending on your personal preferences
  • all those steps always run in the same order, you will never miss one or make other mistakes
  • you can add new features to your build script easily (e.g. running unit tests before packaging; you're always running them before building a release, aren't you?)
  • I tend to start forgetting about the correct order of build steps, especially when I haven't worked on a project for some time. My Gradle/Ant/Maven script does not forget because it lives in Subversion/Git. I can go back to any point in time and re-run that build. No matter what the steps where back then. This is important if you have past releases that you need to maintain for some time.
  • a build script works on multiple machines. Telling your coworker about build steps tends to be error prone. Sometimes there are some many things that need to be done manually, that only certain people can do a release. Most others don't know the ins and outs of creating a release. This might not be a reason for you, as mentioned you're working alone.
  • a build script is independent from your IDE. You can switch to Eclipse, Netbeans or a Continuous Integration system and still be sure that your builds will still work
  • you can automate tedious steps ("I always need to create this folder for a release, create a subfolder documentation in there and move the javadoc in there")
  • you can design your build scripts to always create your builds from scratch. That avoids problems with files left over from some previous builds ending up from a previous build in release.
  • developing more apps just requires you to copy a build script to have the process in place
  • IDEs don't contain workflow editors to support complex build processes (well, you could use macro recording in IDEA...)
  • build scripts are the only real viable solution to integrate external tools (e.g. obfuscators) into your build process

Hope that helps,

Comment actions Permalink

P.S: There is Tools > Generate Ant Build... which will get you started.

Comment actions Permalink

I agree there are lots of benefits to using ANT, but none of those in that list apply to me right now. I'm a sole developer, nothing to share, no team, no build server, and I have just the two build modes, debug, and release, both of which are very quick and easy in the IDE. So although ANT has many benefits they're just inapplicable right now, and my goal is to "obfuscate the release build investing as little time as possible", and learning Ant looks counter to that goal. I have no experience with Ant, so the result will be me spending hours poring over the docs when I should be fixing bugs and adding features to my app.

I see the option under Build -> Generate Ant Build, but it produces two files that mean nothing to me at this point, and as I say my goal is to AVOID spending hours on this, not pick up another thing to learn when I'm on tight deadlines. You suggest it's essential to learn all this, and in an ideal world you're right, but the soon-to-be-released Eclipse add-ins from Google for Android dev will bring obfuscation in as a default part of the build process. I know our instinct as programmers is to understand everything, but something it's more important to just get the job done. I'm looking for the quickest and easiest way to get the job done. taking on a tool I am unfamiliar with doesn't seem the most obvious way to achieve that.

Do the plugins for yGuard and Proguard for IDEA not work? Is anyone using them?

Comment actions Permalink

I'm a sole developer, nothing to share, no team

So you are a "corner case".

my goal is to AVOID spending hours on this, not pick up another thing to learn when I'm on tight deadlines

You always will be on tight deadlines. Understanding how to write an ANT
script I rate as a must-have competence for a Java developer. But in
contrast with Dirk's suggestion, I'd rather would start with a small
hand-written ANT file instead of a generated one. (1)

I'm looking for the quickest and easiest way to get the job done.

ANT is. If you would have started with a simple ANT build file yesterday,
you already would have been ready and would save time with each new
requirement or project change in the future.


(1) When learning a new programming language, I prefer to start with the
basics: how to compile from command line. This helped me a lot to better
understand how things play together.

Comment actions Permalink

I agree Ant is important, but it's a matter of priorities in terms of what skills I pick up in what order. No-one can learn everything instantly. Inside a few weeks months I've re-learnt Java, learnt the Android platform, and learnt the functions I need in both Eclipse and IDEA. I'm doing very well with my progress, but amongst all of this I have an app to write! I have one 80% complete to a good standard, I'm very pleased to be at this point after a relatively short period of time. The reality is that if I had spent time yesterday learning how to build my project with Ant I would not have fixes the series of bugs I fixed yesterday and implemented the features I implemented yesterday. Picking up new skills has an initial cost, and we all have to decide when is the right time to incur that cost (time or money, for me both).

You seem to be saying that because Ant is easy for you I can click my fingers and be good at it too. I'm not you, I have time constraints, you have experience I don't. Adding obfuscation to my project using Ant is far from quick. It looks like the best solution is to use the new integrations from Google and dump IDEA to go back to Eclipse (a shame, but Android apps need obfuscating and it is clearly a tedious, inefficient PITA to do it with IDEA)

I agree about the value of going back to basics, but only for education, not in projects where that deeper-level work adds no value. I used to write ARM assembly language in the 1980s, but clearly I wouldn't write my Android apps in ARM assembly, it would be absurd. And to me re-creating the IDE's build process using parallel scripts is inferior to clicking a button marked "Build Release Version (Obfuscated)" when all I want to do is obfuscate and have no need for team builds, etc.

Are lone-developers a rare exception? Clearly not.

Comment actions Permalink

Well, you've asked for the quickest solution. I told you. It definitely
takes longer to integrate ProGuard into IDEA - for Jetbrains or for you
writing an IDEA plug-in or providing an IDEA patch - than using ANT. If you
don't want to use that option, I can't help you further.



Please sign in to leave a comment.