Tuesday, March 2, 2010

Proguard 4.x error - java.lang.ArrayIndexOutOfBoundsException - How to fix it

Using Proguard to obfuscate your classes in your midlets is a must. The jar size is reduced and the code is optimized.

But when I obfuscated my app an error is displayed and the jar is not obfustaced. The error is similar to:

java.lang.ArrayIndexOutOfBoundsException: 2

WTF is this? :)

I don't know why, I didn't download the source of proguard (BTW this amazing tool is opensource)

How to fix it? Two options:
* disable optimization. It's not the best option but it helps. Use parameter -dontoptimize
* disable optimization partially. I used this option. The last proguard has many parameters for optimization, and I found the parameter that worked in my midlet:

-optimizations !method/marking/static

this means the optimizer will avoid marking methods as static.

It worked for me, I hope it works for you.

Proguard optimizations site: http://proguard.sourceforge.net/manual/optimizations.html

3 comments:

  1. Great help. Spent hours trying to sort through this, but your entry here quickly got me on the right track. In my case, !method/removal/* did the trick.

    ReplyDelete
  2. Thanks both of you, especially Anonymous - you guys saved my day! :)

    ReplyDelete
  3. That works for me, thanks for the tip!!

    ReplyDelete