Compile v8 arm, arm64, ia32

Quick guide on how to compile v8 8.4-lkgr for Android on Ubuntu in one copy/paste script. I use this script regularly, so it is well tested.

# Install git:
sudo apt install git

# Install depot tools
# Follow instructions https://v8.dev/docs/source-code.
# Fetch v8 source code.
# Use the branch of your choice. In will use 8.0-lkgr (last known good release).
# I'd advise always using -lkgr branches
fetch v8
cd v8
git pull
git checkout 8.0-lkgr

# Enter v8 folder.
cd v8

# Install all dependencies, ndk, sdk, etc.
# This may take a while. It downloads android tools: sdk+ndk, etc.
build/install-build-deps-android.sh

# Set android target. This op might also take some time.
echo "target_os = ['android']" >> ../.gclient && gclient sync

# Generate compilation target: 
# Change android_arm.release to the folder name of your choice, 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`
#
# Use this to compile for arm/arm64
tools/dev/v8gen.py arm.release

# Use this to compile for x86
tools/dev/v8gen.py ia32.release

# Edit gn 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` 
#
# E.g.:
# 
# v8_enable_i18n_support= false
# is_debug = false
# symbol_level = 0
# target_cpu = "arm"
# v8_use_external_startup_data = false
# v8_monolithic = true
# 
# Optionally set `target_cpu="arm64"` or `target_cpu="x86"` (if ia32 was used)
#
# for a full argument list, run: 
#   `gn args --list arm.release`
#
vi out.gn/android_arm.release/args.gn

# This is my file contents:
#
# android_unstripped_runtime_outputs = false
# is_component_build = false
# is_debug = false
# symbol_level = 1
# target_cpu = "arm64"
# target_os = "android"
# use_goma = false
# v8_target_cpu = "arm64"
# v8_use_external_startup_data = false
# v8_enable_i18n_support= false
# v8_android_log_stdout = true
# v8_static_library = true
# v8_monolithic = true

# 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

# Fat lib file has been generated by v8_monolithic parameter at
# out.gn/<e.g. android_arm.release>/obj/libv8_monolithic.a 

# source headers, for inspector compilation.
mkdir -p src/base/platform
mkdir -p src/common
mkdir -p src/inspector
mkdir -p src/json

cp -R ../../../../src/common/*.h ./src/common
cp -R ../../../../src/base/*.h ./src/base
cp -R ../../../../src/base/platform/*.h ./src/base/platform
cp -R ../../../../src/inspector/*.h ./src/inspector
cp -R ../../../../src/json/*.h ./src/json

# copy v8 compilation header files:
cp -R ../../../../include ./

# For compilation on Android, always use the same ndk as 
# `gclient sync` downloaded. 
# 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"
use_goma = false
target_os = "android"
v8_use_external_startup_data = false
v8_enable_i18n_support = false
v8_monolithic = true

Published by ibon

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

2 thoughts on “Compile v8 arm, arm64, ia32

  1. Hi
    I needed to built v8 with NDK version 21 which was different than what gclient sync downloaded. So i changed the ndk paths used by v8 to refer to NDK version 21 paths. After building for arm64 and x86_64 and using libv8_monolith.a files in android studio, the project runs successfully.
    But for 32-bit devices ( i.e. arm and x86), though the build is successful, the android project crashes. I am not able to find any specific argument that might be needed for building v8 for 32-bit devices. Could you please suggest where i might be wrong?
    I have used the following arguments to build v8 for arm:

    target_os = “android”

    is_debug = true

    is_component_build = false

    target_cpu = “arm”

    v8_target_cpu = “arm”

    v8_enable_pointer_compression = false

    clang_use_chrome_plugins = false

    v8_monolithic=true

    v8_use_external_startup_data=false

    symbol_level=2

    v8_enable_i18n_support=false

    Like

    1. That config file looks correct to me.
      Since you have debug+symbol_level, you should be able to get an accurate grasp of when things derail.
      For x86, you need to set `target_cpu = “x86″` (simulator). But the arm should work straight away. Maybe you can share some stack traces.

      Like

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: