2

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!

Will Tice
  • 434
  • 4
  • 17

1 Answers1

2

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

Community
  • 1
  • 1
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • I don't appear to have a build.properties file like the suggestion in your link. I tried commenting it out like so: "# proguard.config=proguard.cfg". Then I cleaned the project and rebuilt it, but the problem persists. – Will Tice Dec 09 '14 at 19:06
  • @WillTice How did you enable proguard in the first place? – Elliott Frisch Dec 09 '14 at 19:07
  • I enabled it by adding the line proguard.config=proguard.cfg. You got me thinking though that maybe it isn't that Proguard is running when it shouldn't be, but rather that when building with Proguard it's doing something extra that it isn't doing normally. I'm investigating this now, I think it may be my -injars line in proguard.cfg. – Will Tice Dec 09 '14 at 19:30
  • 1
    Thanks, you helped me figure it out! So here's what the problem was. My Android project is set up to depend on another project. In the Project Properties -> Java Build Path -> Order and Export panel, I had to uncheck the dependency for the other project in order for it to be obfuscatable by Proguard, using the -injars command to include it. This is why Proguard worked but Run As didn't. The solution is to simply check the box when debugging, and uncheck it when I export with Proguard. (Told you it might be a stupid question!) I also had to clean the project and rebuild it after doing this. – Will Tice Dec 09 '14 at 19:39