9

I want to add some scripting support to my android application. My app is not web based, it is just a common app, written in Java.

I need to choose scripting language and its interpreter implementation for embedding. As for language I prefer JavaScript (or better to say ECMAScript) because it doesn't have any built-in stuff to interact with user (I mean printing smth and so on), that's just what I need (I just want to add a couple of functions and/or objects to interact with some of my app's logic). And another reason is that I have only very little experience with Python and have not at all with Ruby, Lua and others, and as far as I can concern more people are familiar with JavaScript.

User scripts in my app are expected to be really small and they will be executed not too often, that's why scripting engine speed doesn't matter. The main criteria that matters is additional binary apk size, implied by interpretor engine. It should be as small as possible. Ideally around couple of dozens of kilos, and not more then 150-200Kb in any case (after ProGuard of course). I don't need full language support, e.g. I'll be absolutely happy without regexps. Another important thing is engine's memory consumption (but it is much less important, then binary size).

I know (from https://stackoverflow.com/a/11973689/52607 and Use V8 JavaScript engine to execute JS lib without webview) that modern android devices already have v8 JavaScript engine on board. But I can't figure out, how to use it (without embedding a copy inside my app). According to first linked answer by soulseekah I can link against libwebcore.so using ndk. But v8 has C++, not C API and all names are mangled in .so preventing linker from finding them. I'v managed to compile my own copy of v8 from its source and use it in my app through ndk, but the resulting .so is 17Mb (!!!), that is very far from being acceptable.

So my question is, how can I use v8 shipped with android devices (on devices really having it) through NDK or in some other way ? Or, if it is not possible, are there another scripting engines (for JavaScript or for other language), that meet my binary size requirements ? Or may be there is some trick with v8, that allows to make it much smaller in size (may be at cost of speed or some language features support) ?

Community
  • 1
  • 1
Meteorite
  • 903
  • 1
  • 9
  • 13

1 Answers1

-2

Little late on this question but anyway. I'm using rhino jar and it is working well. About builded v8 .so . Maybe you need to also run arm-eabi-strip

  • As far, as I remember, v8 .so was 17Mb after stripping... Rhino's size is almost acceptable, but it gives too much freedom. You need to carefully define security policy to prevent scripts from doing Bad Things, and I just don't need all Rhino's power. I ended up with embedding [this Lua VM](https://code.google.com/p/kahlua/). I embedded only VM without compiler (scripts must be precompiled to be used in my app). After throwing out most parts of standard Lua library and ProGuarding it added less then 20Kb to my apk size. – Meteorite May 07 '14 at 19:58
  • 1
    Just found out some interesting blog about embedding javascript in android app. After some build params tweaks size is 8M. Still too much for single app. _Even if we disable the internationalization API (with the i18nsupport=off switch) the app still needs 8MB (+7MB) which is much larger than the respective Rhino app which needed 3.6MB (+2.6MB) of disk space._ Ducktape also looks interesting. http://www.skyscanner.net/blogs/developing-mobile-cross-platform-library-part-3-javascript – SandroProxy support May 20 '14 at 12:54
  • Rhino works but it is quite slow, the question wanted V8 – epx Aug 23 '15 at 04:37