2:52 pm
Monday, 15 August 2022 (HKT)
Time in Hong Kong


拉取步骤

拉取depot_tools

1
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
1
export PATH="$PATH:/path/to/depot_tools"

拉取Android Chromium源码

1
mkdir /chromium && cd /chromium
1
fetch --nohooks --no-history android
1
gclient sync

接下来继续之前,额外一个可选步骤:切换到指定版本(查阅“切换到指定版本”节)

1
2
3
cd src
./build/install-build-deps-android.sh
gclient runhooks

代码拉取完成。

(可选)查看当前版本

1
2
cd src
cat chrome/VERSION

(可选)切换到指定版本

1
2
3
4
cd src
git fetch origin 74.0.3729.186
git checkout -b 74.0.3729.186 FETCH_HEAD
gclient sync --with_branch_heads -D

(用于平时更新代码)同步一下代码

1
gclient sync

编译步骤

1
gn gen out/Release --args='target_os="android" is_debug=false is_official_build=true enable_nacl=false is_chrome_branded=false use_official_google_api_keys=false enable_resource_whitelist_generation=true ffmpeg_branding="Chrome" proprietary_codecs=true enable_remoting=true' 
1
ninja -C out/Release/ system_webview_apk -j32

或者使用autoninja进行编译:

1
autoninja -C out/Release/ system_webview_apk 

FAQ

Error: Could not create the Java Virtual Machine.

编译需要JDK,而且是特定版本的JDK(截至目前要求JDK 8)

JDK版本是可以动态切换的,查看(并修改)JDK版本:

1
2
sudo update-alternatives --config java  
sudo update-alternatives --config javac

根据提示输入数字,选择jdk 8即可

命令输出长得像下面这样:

1
2
3
4
5
6
7
There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode

参考

  1. https://chromium.googlesource.com/chromium/src/+/master/docs/android_build_instructions.md