Compile v8 arm, arm64, ia32

It’s been a long time since I last compiled v8 for arm 7 Android, and honestly, lots of things have changed. No more scons, etc… This is going to be a quick guide on how to compile v8 5.5 for Android on CentOS or Ubuntu. The list of steps is not big, but hold tight.

I use this script regularly, and is updated over the versions. I have recently used it to successfully compile and upgrade my projects to v8 v8.

# Install git:
sudo yum install git
# Install 32 bit library support (multiarch):
sudo yum install glibc-devel.i686
# Install depot tools
# Follow instructions here.
# Fetch v8 source code.
# Use the branch of your choice. In my case latest 5.5 stable.
fetch v8
cd v8
git pull
git checkout 5.5-lkgr
# If in ubuntu, you'll really want to execute:
#    build/install-build-deps-android.sh
# Set android target: 
# This may take a while. It downloads android tools: sdk+ndk, etc.
echo "target_os = ['android']" >> ../.gclient && gclient sync
# Generate compilation target: 
# Change android_arm.release for your favorite folder name, in this
# case: out.gn/android_arm.release
#
# you can have a full list of options by running:
#   `tools/dev/v8gen.py list -m client.v8.ports`
tools/dev/v8gen.py gen -m client.v8.ports -b "V8 Android Arm - builder" android_arm.release
# Edit ninja configuration file: 
# I’d recommend disabling icu support, and set 
# symbol_level=0 for faster compilation and thinner
# output libs. You can get the whole list of 
# compilation options by executing: 
# `gn args out.gn/android_arm.release —-list` 
# 
# You must also disable distributed compiler goma.
#
# E.g.:
# 
# v8_enable_i18n_support= false
# is_debug = false
# symbol_level = 0
# target_cpu = "arm"
# enable_goma = false
# v8_use_external_startup_data = false
# 
# Optionally set `target_cpu="arm64"`
#
# for a full argument list, run: 
#   `gn args --list android_arm.release`
#
vi out.gn/android_arm.release/args.gn
# Compile target: 
# This may take up to 1 hour depending on your setup.
# Use a -j value suitable for your system.
ninja -C out.gn/android_arm.release -j 4
# Create fat lib files. 
# You also could add all .* files into one single library.
# 
cd out.gn/android_arm.release/obj
mkdir libs
cd libs
# one lib to rule them all.
ar -rcsD libv8_base.a ../v8_base/*.o
ar -rcsD libv8_base.a ../v8_libbase/*.o
ar -rcsD libv8_base.a ../v8_libsampler/*.o
ar -rcsD libv8_base.a ../v8_libplatform/*.o 
ar -rcsD libv8_base.a ../src/inspector/inspector/*.o
# preferred snapshot type: linked into binary.
ar -rcsD libv8_snapshot.a ../v8_snapshot/*.o 
# depending on snapshot options, you should left out 
# v8_snapshot files and include any of these other libs.
ar -rcsD libv8_nosnapshot.a ../v8_nosnapshot/*.o
ar -rcsD libv8_external_snapshot.a ../v8_external_snapshot/*.o
# source headers, for inspector compilation.
mkdir -p src/base/platform
cp -R ../../../../src/*.h ./src
cp -R ../../../../src/base/*.h ./src/base
cp -R ../../../../src/base/platform/*.h ./src/base/platform
# copy v8 compilation header files:
cp -R ../../../../include ./
# For compilation on Android, always use the same ndk as 
# `gclient sync` downloaded. 
# As of the time of this writing it was `ndk r12b`
# Enjoy v8 embedded in an Android app

Compile for Android emulator

tools/dev/v8gen.py gen ia32.release
# edit out.gn/ia32.release/args.gn, to contain the following:
is_debug = false
target_cpu = "x86"
target_os = "android"
v8_enable_i18n_support = false

Published by ibon

Chocolate engineer, software eater. Data visualisation at Workday. Past: Platochat, SdkBox, Chukong, Ludei.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: