Javascript engine options for Android (non-WebKit)

2.1k Views Asked by At

We have created a HTML5 + Javascript application and would like to port it to Android. We already know WebKit is not capable to run the HTML5 app because

  • Heterogenous Android codebase supports the latest HTML5 feats badly

  • We use WebGL

  • Complex HTML5 user interface is too slow to be rendered on Android WebKit

However our core application logic still resides in Javascript.

Now are are looking for ways to

  • Run the application logic directly ported (copied) Javascript

  • bind itself to Android Java UI API easily

  • Build native Android UI around this Javascript logic

  • Create WebGL compatible bindings for Android OpenGL ES and access graphics API from Javascript

  • Hopefully JIT or decent performance

What options we have for custom JS runtimes on Android? I know Firefox Aurora does this already; Firefox is largerly JS based app and now they switched from XUL to native Android UI in Aurora builds.

The resulting application must be production quality and subject to Android Market distribution.

2

There are 2 best solutions below

1
On

If you want all of HTML5 (and particularly WebGL), then you'll need the DOM APIs as well, which are not part of SpiderMonkey. SpiderMonkey is just the core Javascript language interpreter, and doesn't contain browser-specific bindings like the window/document/element objects. So really if you want HTML5+JS on Android you'll have to embed the entire browser, which is not easily doable with Firefox Aurora.

2
On

Take a look at the new Native UI code for Firefox Mobile, it embeds Gecko (and consequently SpiderMonkey), and has all the content capabilities of Firefox for desktop, which includes WebGL.

Note, though, that Firefox Mobile used to do something very similar to what you want: embed (and provide the necessary device access APIs to) the Gecko engine and then do all the UI and application logic with XUL and JavaScript. This lead to significant performance issues, and is the main reason we're now working on a Java UI for Mobile.

As staktrace mentioned, if you want WebGL you'll need the DOM, and that means you'll need Gecko in its entirety. Or you can use OpenGL ES directly with Android's Graphic APIs. It may be possible to extract or reuse some of Gecko's WebGL code and create your own OpenGL JavaScript binding, but it won't be WebGL.