Skip to content

Instantly share code, notes, and snippets.

@hyperandroid
Created February 11, 2022 12:53
Show Gist options
  • Save hyperandroid/85cdbd385e9997893dc342fd6b365e12 to your computer and use it in GitHub Desktop.
Save hyperandroid/85cdbd385e9997893dc342fd6b365e12 to your computer and use it in GitHub Desktop.
# 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.4-lkgr (last known good release).
# I'd advise always using -lkgr branches
fetch v8
cd v8
git pull
git checkout 8.4-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 will take some time, ndk alone is +1Gb
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
#
# 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`
#
# Optionally set `target_cpu="arm64"` or `target_cpu="x86"` (if ia32 was used)
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 = "arm"
target_os = "android"
use_goma = false
use_custom_libcxx = false
use_custom_libcxx_for_host = false
v8_target_cpu = "arm"
v8_use_external_startup_data = false
v8_enable_i18n_support= false
v8_android_log_stdout = true
v8_static_library = true
v8_monolithic = true
v8_enable_pointer_compression = false
# to compile arm64, just change target_cpu and v8_target_cpu to arm64
# Compile target:
# This may take up to 1 hour depending on your setup.
# Optionally use a -j value suitable for your system.
ninja -C out.gn/android_arm.release v8_monolithic
# 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
mkdir -p src/utils
mkdir -p src/init
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
cp -R ../../../../src/utils/*.h ./src/utils
cp -R ../../../../src/init/*.h ./src/init
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment