dragome/dragome-sdk

Proguard Obfuscate support

Closed this issue · 10 comments

Obfuscate should be supported, it will reduce javascript size a lot.

The implementation in mind is to execute ChainedInstrumentationDragomeConfigurator#filterClassPath first (it does now), then execute ClasspathFileFilter listener to remove individual class and generate a Merge_removed..jar . After the jar with excluded classes it pass to proguard to do its job by removing unnecessary code and renaming package/class/method names.

I think it could be achieved touching only proguard configuration, to enable obfuscation and configuring a set of classes necessarily excluded such as the ones required for reflection, and the ones that are referenced hardcoded in some ScriptHelper methods calls and compiler usage.

setClasspathFilter listener wont work after obfuscation because it will have those crazy names so it needs to call it before proguard ( or call proguard multiple times? one for removing unused code and call it again later after setClasspathFilter listener for obfuscation ? )

It says that a basic Relection like forName, getField, getMethod, etc, is detected and handled for us but only testing will tell.

Do you remember where can I find all the hardcoded codes?

edit: I can only think of delegator class methods. that will make calls to wrong js code.

Got obfuscation working.
Only a few classes and all Delegator classes is not obfuscated.

Comparing Libgdx tests javascript size :
No ProGuard: 10.4 MB
Shrink = 3.39 MB
Shrink + Obfuscate = 2.60 MB
Shrink + Obfuscate + yuicompressor = 1.94 MB

can reduce a bit more if Delegator classes is obfuscated.

wow! really great!! I'll making some tests over wro4j to activate yuicompressor.

for yuicompressor you will need to remove KeyboardEvent#getChar() method. it complains about char not being valid.

ok, but I cannot find a js yui compressor working on wro4j, I've found only for css.
Did you try minifying with Google Closure compressor?

I used cmd for yui compressor. we can just execute it without wro4j.

I didnt try google Closure. I will take a look.

Google Closure compressor gives a bunch of warnings unreachable code.
output is 1.82 MB.

Seems better than yui but the warnings not sure if its using its full power or it will work fine in the browser.

Last time I test it there was no way to perform full compression, it used to throw multiple errors and sometimes hangs.

I updated my obfuscation branch xpenatan@254da07

I tried but its not possible to use shrink and obfuscation together. There is a weird bug in bcel that dont know how to handle classes with same name and mess it up ( like a bunch of a,b,c,d,.. classes in each package). So unique name "-useuniqueclassmembernames" is required but dont work with shrink.

It needs another pass. I dont see a problem using again for obfuscation. gdx tests compile in 5-6 seconds.