Android SystemWebView Chromium源码拉取与编译

1,234 阅读1分钟

拉取步骤

拉取depot_tools

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

拉取Android Chromium源码

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

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

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

代码拉取完成。

(可选)查看当前版本

cd src
cat chrome/VERSION

(可选)切换到指定版本

cd src
git fetch origin 74.0.3729.186
git checkout -b 74.0.3729.186 FETCH_HEAD
gclient sync --with_branch_heads -D

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

gclient sync

编译步骤

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' 
ninja -C out/Release/ system_webview_apk -j32

或者使用autoninja进行编译:

autoninja -C out/Release/ system_webview_apk 

FAQ

Error: Could not create the Java Virtual Machine.

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

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

sudo update-alternatives --config java  
sudo update-alternatives --config javac

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

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

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. chromium.googlesource.com/chromium/sr…