如何编译 Chrome for Android

这篇博客详细介绍了如何在2014年编译 Chrome for Android,从下载 depot_tools 到配置 GYP,再到安装 Java JDK,一步步教你如何构建 Content shell 或 WebView shell,并提供了在 Ubuntu 系统上进行调试的提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2014.5 更新


下载 depot_tools

下载 depot_tools(默认下载到当前用户主文件夹下的 chromium 子目录,自行根据需要修改,下载完毕后需要将 depot_tools 的目录添加到 PATH)

cd ~
mkdir chromium
cd chromium

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 

下载源代码和编译所需的第三方工具/库

fetch --nohooks android --nosvn=True
cd src
git checkout master

# if you are building for Android:
./build/install-build-deps-android.sh

gclient sync --nohooks

配置 GYP

~/chromium$ echo "{ 'GYP_DEFINES': 'OS=android', }" > chromium.gyp_env

~/chromium$ gclient runhooks

安装 Java JDK(如果已经安装可以跳过)

# 安装 Open JDK 1.7

~/chromium$ sudo apt-get install openjdk-7-jdk

# 配置为默认 JDK

sudo update-alternatives --config javac
sudo update-alternatives --config java
sudo update-alternatives --config javaws
sudo update-alternatives --config javap
sudo update-alternatives --config jar
sudo update-alternatives --config jarsigner

编译 Content shell

# 编译 Release 版本并安装到手机上

~/chromium/src$ ninja -C out/Release content_shell_apk

~/chromium/src$ build/android/adb_install_apk.py --apk ContentShell.apk --release

# 编译 Debug 版本并安装到手机上,Debug 版本可用于调试

~/chromium/src$ ninja -C out/Debug content_shell_apk

~/chromium/src$ build/android/adb_install_apk.py --apk ContentShell.apk --debug


如果是编译 WebView shell

~/chromium/src$ ninja -C out/Release android_webview_apk
~/chromium/src$ build/android/adb_install_apk.py --apk AndroidWebView.apk --apk_package org.chromium.android_webview.shell --release

运行 Content shell

~/chromium/src$ . build/android/envsetup.sh

~/chromium/src$ build/android/adb_run_content_shell  http://example.com

调试 Content shell

如果是中文 Ubuntu,需要先修改 src/build/android/adb_gdb,找到下面这个一段 -

if [ "$STATE" != "Running" ]; then
  echo "ERROR: GDBServer could not attach to PID $PID!"
  echo "Failure log (use --verbose for more information):"
  cat $GDBSERVER_LOG
  exit 1
fi

将第一行的"Running"修改为"运行中",然后运行 -

~/chromium/src$ build/android/adb_gdb_content_shell

# 默认调试主进程,如果要调试 sandboxed 进程(需要 adb root,使用参数 --help 查看更多选项)

~/chromium/src$ build/android/adb_gdb_content_shell --sanboxed

参考索引

Get the Code

Build instructions for Chromium for Android

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值