dragome / dragome-sdk

Dragome is a tool for creating client side web applications in pure Java (JVM) language.
http://www.dragome.com
Other
80 stars 20 forks source link

Proguard Obfuscate support #124

Closed xpenatan closed 7 years ago

xpenatan commented 8 years ago

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.

fpetrola commented 8 years ago

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.

xpenatan commented 8 years ago

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.

xpenatan commented 8 years ago

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.

fpetrola commented 8 years ago

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

xpenatan commented 8 years ago

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

fpetrola commented 8 years ago

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?

xpenatan commented 8 years ago

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

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

xpenatan commented 8 years ago

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.

fpetrola commented 8 years ago

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

xpenatan commented 7 years ago

I updated my obfuscation branch https://github.com/xpenatan/dragome-sdk/commit/254da07698fd33f23f3e272ed291733762a27be9

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.