4

I have recently converted a project from eclipse/ant to using Android Studio/Gradle. My debug build works fine but when I attempt to do a release build with proguard enabled it fails with the following error

16:26:13.437 [ERROR] [system.err] Unexpected error while computing stack sizes:
16:26:13.438 [ERROR] [system.err]   Class       = [com/a/a/a/d/d]
16:26:13.438 [ERROR] [system.err]   Method      = [<clinit>()V]
16:26:13.438 [ERROR] [system.err]   Exception   = [java.lang.IllegalArgumentException] (Stack size becomes negative after instruction [143] swap in [com/a/a/a/d/d.<clinit>()V])

I have used the same proguard.txt for my eclipse project and it worked fine so it suggests there is some kind of problem with the Gradle Android plugin. Has anyone encountered a similar problem? My proguard config - http://pastebin.com/2gsNUmeD and full gradle output http://pastebin.com/TAvMUSrR

Greg McGowan
  • 1,360
  • 1
  • 10
  • 20

1 Answers1

2

ProGuard should indeed behave identically in Ant, Eclipse, and Gradle. You should check if your builds use different versions of ProGuard. You can see the version in the console log. If you know which ProGuard jar is being used, you can also type java -jar proguard.jar to get the version.

The error message suggests a bug in ProGuard's optimization step. Hopefully the bug occurs in an older version and not in newer versions. You can then simply upgrade the jar. Otherwise, you can report it on ProGuard's bug tracker, preferably with sufficient information to reproduce the problem. As a workaround, you can disable optimization with the option -dontoptimize.

Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • 1
    It's ProGuard 4.9 that is used by the android gradle plugin. If I try it with -dontoptimize then that works okay. I'll see if I can find a small sample that reproduces the problem. – Greg McGowan Sep 23 '13 at 16:26
  • Hi, thanks for your answer Eric. I want to remove all logs from my build via ProGuard, and am doing so via your answer [here](http://stackoverflow.com/a/13327603/2048653). But I need to use `proguard-android-optimize.txt`, inserting `-dontoptimize` into my app's `proguard-rules.txt` would null out the effects of the optimize proguard configuration. More importantly, I wouldn't be able to remove my logs if I use `-dontoptimize`. Any way we can accomplish this? I'm using Android Studio and I've upgrade my Proguard jar to version 5.0 in the `{sdkdir}/tools/proguard/lib` folder already. – waynesford Sep 25 '14 at 20:30
  • @waynesford Ant and Eclipse use `{sdkdir}/tools/proguard/lib/proguard.jar`, but Android Studio and Gradle download and use the Android plugin (currently 0.13.0) and the ProGuard plugin (currently 4.11) from Maven Central. You should check if ProGuard 5.0 helps and then try to convince Gradle to use it. – Eric Lafortune Sep 25 '14 at 23:22
  • gradle-proguard plugin 5.0 still has this issue, and looks like there's no way to use proguard 4.7 in gradle. BTW: add gradle-proguard plugin 5.0 `classpath 'net.sf.proguard:proguard-gradle:5.0'` – andyao Oct 08 '14 at 05:49
  • @andyao If you still see such an error message, please report it on the ProGuard bug tracker (or mail me) with a sample to reproduce it. – Eric Lafortune Oct 09 '14 at 00:03
  • @EricLafortune I am still seeing the same problem with version `5.2.1` http://stackoverflow.com/questions/33595645/stack-size-becomes-negative-after-instruction – learner Nov 08 '15 at 15:33