LiquidPlayer / LiquidCore

Node.js virtual machine for Android and iOS
MIT License
1.01k stars 127 forks source link

Is it possible to reduce file size by removing simulator support? #80

Closed baruchn closed 5 years ago

baruchn commented 5 years ago

I know you did a lot of work to reduce the size of the library but it's still large and takes ~90% of the size of my application. All I need is to run some JS scripts on real devices. Is it possible to remove x86 and x86_64 support to reduce the size in half? Is there anything else that can be done to significantly reduce the size by giving up on advanced features?

screen shot 2019-01-23 at 10 01 26

ericwlange commented 5 years ago

You should use APK splits, which will allow you to specify arm-only APKs. If for some reason this does not work, let me know. It may require a little gradle magic to filter it out.

baruchn commented 5 years ago

I was unable to make it work so far :( I see that Node is responsible for most of the size. Is there a way to use LiquidCore without it?

ericwlange commented 5 years ago

Can you show me what you tried to do that did not work?

You just need to filter out jni/x86*/** from your final APK.

LiquidCore will not work without libnode.so. Node is not very big -- it is V8 (which is embedded in libnode.so) that takes up all the space. Unfortunately that's the javascript engine.

baruchn commented 5 years ago

You meant I should build LiquidCore myself? I thought I can filter it in my own library which uses LiquidCore by using splits { abi { enable true reset() include 'arm64-v8a', 'armeabi-v7a' universalApk false } }

If the V8 engine is very big, why is J2V8 smaller and Duktape is less than a 10th of the size?

ericwlange commented 5 years ago

You shouldn't have to build it yourself (although it is very easy to do so). In your build.gradle you should be able to manage the splits as you have attempted to do. I've never tried this myself, but others have successfully done it with LiquidCore, so I will have to play with it.

Duktape is not built on V8 AFAIK. It is its own javascript engine completely separate from the big 3 -- V8 (Google), JavaScriptCore (Apple) and Spidermonkey (Firefox). It was designed to be compact. I don't know what tradeoffs they made to get there. If it suits your purposes better, you should use it.

J2V8 does use V8, but I don't know what version or with what options. For instance, I use V8 snapshots, which do take up more space, but make V8 start up significantly faster than without them. I optimized for speed & features (ES6, etc.) with size as a secondary goal. And yes, node does take up some space, but just not very much in comparison to v8.

The answer to this with LiquidCore is APK splits. It would be great if someone could post what they did to make them work or submit a PR if something is required in LiquidCore. Otherwise, I will try to do it when I have a moment.

baruchn commented 5 years ago

Thanks for the quick and informative responses. I will keep trying to reduce the size because I like LiquidCore better than the others. It was easiest to setup, has the most intuitive API and performs without errors (so far :)). Will post it here if I'll succeed.

ericwlange commented 5 years ago

So now that I've released 0.6.0, I took a look at this. I followed the instructions in the link I provided before, and it worked exactly as advertised. I added the following in my app's build.gradle:

android {
  ...
  splits {

    // Configures multiple APKs based on ABI.
    abi {

      // Enables building multiple APKs per ABI.
      enable true

      // By default all ABIs are included, so use reset() and include to specify that we only
      // want APKs for x86 and x86_64.

      // Resets the list of ABIs that Gradle should create APKs for to none.
      reset()

      // Specifies a list of ABIs that Gradle should create APKs for.
      include "armeabi-v7a", "arm64-v8a"

      // Specifies that we do not want to also generate a universal APK that includes all ABIs.
      universalApk false
    }
  }
}

And then Build -> Build Bundle(s) / APK(s) -> APK(s) and it generated separate APKs for each ABI. Each one was roughly a third (or less) the size of the universal APK.

Closing. Please re-open if this somehow still doesn't work.