如何编译 Chrome for Android

来源:互联网 发布:百度淘宝推广怎么收费 编辑:程序博客网 时间:2024/05/18 03:41

2014.5 更新


下载 depot_tools

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

cd ~mkdir chromiumcd chromiumgit clone https://chromium.googlesource.com/chromium/tools/depot_tools.git 

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

fetch --nohooks android --nosvn=Truecd srcgit checkout master# if you are building for Android:./build/install-build-deps-android.shgclient 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# 配置为默认 JDKsudo update-alternatives --config javacsudo update-alternatives --config javasudo update-alternatives --config javawssudo update-alternatives --config javapsudo update-alternatives --config jarsudo 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 1fi

将第一行的"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

原创粉丝点击