Will Tice
Will Tice

Reputation: 433

Running Android app from Eclipse after setting up for obfuscation

So, this may be the stupidest question ever, but I can't figure it out.

I set up my project to use Proguard obfuscation when I export the APK. A couple weeks later, here I am making some changes to my app in preparation for an update, and I right click on my project and do Run As -> Android Application, just like I always used to while testing.

I was quite surprised to be greeted with a java.lang.NoClassDefFoundError, on the first line of my main method that references obfuscated code. The code compiles in Eclipse, but when run using Run As -> Android Application, it crashes immediately.

However, if I export an APK from Eclipse and manually install it on my phone, the app runs fine! It takes quite a while to export due to the obfuscation though, and while I'm testing it's a pain to wait for it every single time I want to test a change.

So I'm pretty sure this is related to obfuscation, Proguard, and the Eclipse build process. But I'm not sure exactly what's going wrong, or when.

I've tried cleaning the project, I've tried taking "proguard.config=proguard.cfg" out of my project.properties file. Somewhere along the line, something obfuscation-related happened to my project that makes my app un-runnable without exporting an APK. What causes this?

I was under the impression that doing Run As -> Android Application will NOT invoke Proguard. So what's going on?

(Note: The same thing happens using "Debug As" rather than "Run As")

EDIT 1

I've tried commenting out the proguard.config line in project.properties, cleaning the project, and rebuilding it. Same problem.

Additionally, I tried renaming/removing proguard.cfg, but the problem persisted. Which got me thinking, maybe this isn't an obfuscation-related problem, but rather a project setup problem? But how could it work when exporting an APK yet crash when I Run As -> Android Application? Doesn't make sense.

EDIT 2

The solution is in a comment on the accepted answer. Thank you for putting me on the right path!

Upvotes: 2

Views: 303

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201537

I suggest you disable proguard unless you're doing a release build. When you disable/enable proguard you will need to Project > Clean (and re-build if you don't have Project > Build Automatically checked; Project -> Build or CTRL-B).

Project > Clean

Upvotes: 2

Related Questions