Jasonette / JASONETTE-Android

📡 Native App over HTTP, on Android
https://www.jasonette.com
Other
1.61k stars 270 forks source link

Shrink the binary size #13

Closed gliechtenstein closed 7 years ago

gliechtenstein commented 7 years ago

The reason it's huge is because of a library that's used to process the JSON template--the end result contains one binary for every possible Android device type.

Find another library that's much smaller and don't have this problem.

hakimihamdan88 commented 7 years ago

the apk file quite big

wallabyway commented 7 years ago

consider using gles.js js runtime... 3MB - https://github.com/borisvanschooten/glesjs/tree/master/libs/armeabi

It's a 3MB uncompressed file, compared to liquidPlayer's 22Mb file...

22MB - https://github.com/LiquidPlayer/LiquidCore/blob/master/LiquidCoreAndroid/jni/lib/armeabi-v7a/libnode.so)

gliechtenstein commented 7 years ago

@wallabyway wow 3MB sounds great! But I just took a look and not sure if this is a full fledged javascript engine or a specialized engine for dealing with WebGL only. According to the repo:

Gles.js provides Android WebGL bindings for the Javascript V8 engine

Also,

The goal is not to provide a complete Web browser environment, but just a no-frills direct WebGL canvas, similar to what Ejecta does for IOS.

p.s. We are definitely moving away from the LiquidCore based engine. In fact I've been experimenting with a couple of other engines last couple of days, and have some promising results. Let me know if I'm missing something about this Gles.js. If it's the right alternative I will definitely try it and consider this.

wallabyway commented 7 years ago

The lib file is regular v8 engine. It's specific to arm hence it's small size. Use it as you would regular v8 and ignore any additional webgl bindings (which are external to the .so file anyway).

example apk demos here: http://tmtg.net/glesjs/

gles.js is simply v8 with call outs to OpenGL calls (bindings) and a fake xhr request routing to local android file system files. A small js shim script file is executed first, inside v8 to fake DOM/canvas and regular webGL api. This reduces the effort to port your normal webgl browser code, into gles.js thanks to this shim file.

To quote from the author: "the Javascript V8 engine (ARMv7 architecture). WebGL is directly translated to OpenGL ES, providing what is probably the fastest and smallest engine for running HTML5 games currently available on Android. APK footprint is about 1.5 Mb"

Use the existing libglesjs.so file in the gles project, and follow the example gles cpp/jni code on how to initialize, runScript() / ie. parser()

gliechtenstein commented 7 years ago

Alright guys, starting off 2017 with a slimmer Jasonette!

We switched out the JS engine and now the entire APK size is at 10MB! That's over 75% smaller than before! https://twitter.com/jasonclient/status/815919678409347072

Here's the related PR https://github.com/Jasonette/JASONETTE-Android/pull/42

We took some time to make sure this works for not just the core JSON parser but also other JS files we've been using, including the CSV parser and the RSS parser, thanks to @brad

There is room for making it even smaller (By splitting binary/giving up on x86) but for now I think 10MB is good enough. If anyone wants to look further into this you're welcome to do so though.