Skip to content

cjmxp/ejecta-v8

 
 

Repository files navigation

About

This library ports the excellent EjectaJS (https://github.com/phoboslab/Ejecta) to Android, replacing JavascriptCore with v8 in the process. Think of it as a Javascript engine with Canvas and AJAX but no DOM. If you want fast rendering of a cross-platform Canvas-based JS application this is for - if you have a web application or your JS code accesses the DOM in any way a WebView will be a better choice.

You can download the sample app from Play Store: https://play.google.com/store/apps/details?id=ag.boersego.bgjs.sample

Ejecta-v8 is published under the MIT Open Source License (http://opensource.org/licenses/mit-license.php), as is Ejecta.

This library needs a precompiled, statically linked version of v8 to link against. Currently this is tested against 5.4.500.36 (the latest stable version as of the time of writing). See also Updating v8.

Getting v8 libraries

Precompiled from dropbox

  1. Download the precompiled libs from Dropbox
  2. Unpack into libs/v8

The folder should look like this:

# pwd
~/git/ejecta-v8/libs/v8
# ls
arm64-v8a   armeabi-v7a x86         x86_64

Building v8 from sources

We need NDK r14b. We assume it to be in $NDKPATH:

export ANDROID_NDK_HOME=~/bin/android-ndk-r14b (or wherever you installed it to). Don't forget to add it to the path: export PATH=$PATH:$ANDROID_NDK_HOME

For steps 1 and 2 see also the v8 project documentation.

  1. get depot_tools
  2. Get the sources: fetch v8
  3. cd v8
  4. Checkout correct revision: git checkout origin/5.4.500.36
  5. echo "target_os = ['android']" >> ../.gclient && gclient sync --nohooks as described on v8 wiki
  6. If compiling on Linux, add missing deps: sudo apt-get install libc6-dev-i386 g++-multilib (because compiling errors with some missed libraries)
  7. mkdir out.gn
  8. Create GN build configuration for each ABI. Here for a debug armv7 build: gn gen out.gn/arm.debug --args='is_debug=true is_clang=true is_component_build=true target_os="android" v8_enable_i18n_support=false v8_target_cpu="arm" target_cpu="arm" host_cpu="x64" android_ndk_version="r14b" android_ndk_major_version="14" v8_use_snapshot=false symbol_level=1 v8_enable_verify_heap=true' ..* For a release x86 (32 bit) build with a custom NDK (I prefer to use the latest, in this case r14b): gn gen out.gn/x86.release --args='is_debug=false is_clang=true is_component_build=true target_os="android" v8_enable_i18n_support=false v8_target_cpu="x86" target_cpu="x86" host_cpu="x64" android_ndk_version="r14b" android_ndk_major_version=14 v8_use_snapshot=false v8_enable_verify_heap=true android_ndk_root="/home/build/bin/android-ndk-r14b" ..* You can replace arm with arm64, x86 or x64.
  9. Build with ninja: ninja -C out.gn/arm.debug d8
  10. Go into output folder: cd out.gn/arm.debug/obj
  11. Create a static archive from the resulting object files: $ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar rcvs libv8.a v8/*.o v8_base/*.o v8_libbase/*.o v8_libsampler/*.o v8_nosnapshot/*.o v8_libplatform/*.o v8_libsampler/*.o ..* For arm64, use $ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar rcvs libv8.a v8/*.o v8_base/*.o v8_libbase/*.o v8_libsampler/*.o v8_nosnapshot/*.o v8_libplatform/*.o v8_libsampler/*.o ..* For x86 or x64 use $ANDROID_NDK_HOME/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-ar rcvs libv8.a v8/*.o v8_base/*.o v8_libbase/*.o v8_libsampler/*.o v8_nosnapshot/*.o v8_libplatform/*.o v8_libsampler/*.o
  12. Optionally strip debug symbols. I have never gotten meaningful stack traces out of these anyway, and it speeds linking times up considerably and saves about one GB of space per ABI: $ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip --strip-debug libv8.a
  13. Copy resulting libv8.a into the folder where ndk-build expects it: cp libv8.a $PATH_TO_YOUR_EJECTAV8_CHECKOUT/bgjslibrary/jni/libs/$ABI where $ABI is either armeabi-v7a, arm64-v8a, x86 or x86_64.

Steps 8-14 can be repeated as mentioned for each ABI you want to support. Step 8 can set is_debug to false of course.

Building the sample

Set up at least NDK r14b and make sure it is in the search path.

./gradlew assembleDebug

Updating v8

Find good v8 version: Gist that explains it. See the list of v8 release information

ARMv7 NEON

I opted to compile the arm version with support for NEON instructions, as non-NEON devices are becoming very rare. Make sure to either compile without this option if supporting Tegra 2 is important to you, or disable these devices in the Play Store: List of non-neon devices

About

A port of @PhobosLabs EjectaJS which uses v8 instead of JavaScriptCore.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 62.5%
  • C 32.6%
  • Java 3.7%
  • Other 1.2%