android-plugin icon indicating copy to clipboard operation
android-plugin copied to clipboard

By default, is ProGuard really not optimized?

Open glenviewjeff opened this issue 13 years ago • 3 comments

The wiki guide states, "The plugin allows to run ProGuard optimizations on your classes. This might improve the performance of your application dramatically, but also break it easily. By default, the application is only shrinked by ProGuard, but not optimized."

However, I get consistently different behavior from ProGuard when I configure my build.scala with -dontoptimize.

glenviewjeff avatar Nov 18 '11 04:11 glenviewjeff

can you explain a little more?

jberkel avatar Nov 18 '11 09:11 jberkel

If I add -dontoptimize to my project.scala, it builds fine. If I omit the flag, I get the following error at the end of my build.

...
[info] Dexing D:\Workspaces\Workspace\my-app\target\classes.dex

UNEXPECTED TOP-LEVEL ERROR:
java.lang.AssertionError
        at com.android.dx.dex.code.OutputFinisher.findExpandedOpcodeForInsn(OutputFinisher.java:525)
        at com.android.dx.dex.code.OutputFinisher.calculateReservedCount(OutputFinisher.java:466)
        at com.android.dx.dex.code.OutputFinisher.reserveRegisters(OutputFinisher.java:402)
        at com.android.dx.dex.code.OutputFinisher.finishProcessingAndGetList(OutputFinisher.java:358)
        at com.android.dx.dex.code.DalvCode.finishProcessingIfNecessary(DalvCode.java:108)
        at com.android.dx.dex.code.DalvCode.getInsns(DalvCode.java:185)
        at com.android.dx.dex.file.CodeItem.place0(CodeItem.java:223)
        at com.android.dx.dex.file.OffsettedItem.place(OffsettedItem.java:242)
        at com.android.dx.dex.file.MixedItemSection.placeItems(MixedItemSection.java:312)
        at com.android.dx.dex.file.DexFile.toDex0(DexFile.java:543)
        at com.android.dx.dex.file.DexFile.toDex(DexFile.java:216)
        at com.android.dx.command.dexer.Main.writeDex(Main.java:574)
        at com.android.dx.command.dexer.Main.run(Main.java:218)
        at com.android.dx.command.dexer.Main.main(Main.java:174)
        at com.android.dx.command.Main.main(Main.java:95)
[error] {file:/D:/Workspaces/Workspace/my-app/}My App/android:dx: Nonzero exit value: 3
[error] Total time: 78 s, completed Nov 18, 2011 12:24:27 PM

If I omit the -dontoptimize, the build fails differently:

...
Note: You're ignoring all warnings!
Unexpected error while evaluating instruction:
  Class       = [roboguice/activity/RoboMapActivity]
  Method      = [onCreate(Landroid/os/Bundle;)V]
  Instruction = [42] invokevirtual #8
  Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [android/app/Activity] and [roboguice/activity/RoboMapActivity])
Unexpected error while performing partial evaluation:
  Class       = [roboguice/activity/RoboMapActivity]
  Method      = [onCreate(Landroid/os/Bundle;)V]
  Exception   = [java.lang.IllegalArgumentException] (Can't find common super class of [android/app/Activity] and [roboguice/activity/RoboMapActivity])
[error] {file:/D:/Workspaces/Workspace/my-app/}My App/android:proguard: java.lang.IllegalArgumentException: Can't find common super class of [android/app/Activity] and [roboguice/activity/RoboMapActivity]
[error] Total time: 50 s, completed Nov 18, 2011 12:43:19 PM

glenviewjeff avatar Nov 18 '11 18:11 glenviewjeff

I updated the wiki to document that optimization is on by default.

glenviewjeff avatar Nov 21 '11 15:11 glenviewjeff