中文说明:http://www.jianshu.com/p/5fce18cbe016
硬件:thinkpad x220 8G i5 1T 7200转硬盘。
系统:UbuntuX64 1504桌面版本。
:腾讯cvm 多伦多一区 操作系统 CentOS 7.2 64位 CPU 1核 内存 2GB 系统盘 20GB(云硬盘) 公网带宽 1Mbps,搭建。
sudo apt-get install git
cd $HOME
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=$PATH:$HOME/depot_tools
# 或者 vim ~/.bashrc
export PATH=$PATH:$HOME/depot_tools
git config --global user.name "username"
git config --global user.email "[email protected]"
git config --global core.autocrlf false
git config --global core.filemode false
git config --global color.ui true
安装java jdk,并且设置java环境变量
vim /etc/profile
....
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
# c++arm编译器
g++-arm-linux-gnueabihf
# 使用clang编译
clang
gperf
gnu++
c++11
sudo apt-get install gcc-4.9-multilib
sudo apt-get install g++-4.9-multilib
sudo apt-get install c++-4.9-multilib
sudo apt-get install aptitude
aptitude install libc6:i386
# 好像这个比较重要
sudo apt-get install linux-libc-dev:i386
sudo apt-get install zlib1g:i386
sudo apt-get install lib32z1
sudo apt-get install apt-file
sudo apt-file update
sudo apt-get install lib32z1 libx32z1 zlib1g
sudo apt-get install bison
mkdir -p $HOME/chromium && cd $HOME/chromium
fetch --nohooks chromium
# 如果fetch 方式失败了,并且已经存在$HOME/chromium/.gclient,可以使用gclient sync同步代码
# 或者删除$HOME/chromium/.gclient后,继续使用 fetch --nohooks chromium 获取代码
gclient sync
cd $HOME/chromium/src
# 上面获取的代码是最新版本,并不是稳定版本。
# 一般需要切换到稳定版本的分支
# 切换到release分支,参考:http://www.chromium.org/developers/how-tos/get-the-code/working-with-release-branches
# 使用 git fetch --tags 获取所有tag标签到本地仓库
git fetch --tags
# 如果此时直接使用 git fetch --all,并不能把远程仓库的所有分支都拉到本地仓库
# git fetch --all
# git branch -a # 本地只有有限的几个分支
# 在 http://www.chromium.org/developers/calendar 找到稳定版本的tag号,切换出本地分支
git checkout -b b2785 53.0.2785.134
# 切换到一个分支后,再运行git fetch --all,够得所有的本地分支。
git fetch --all
# git branch -a # 本地出现所有分支 head
# 后面可以切换到任何分支,本地参考会出现所有分支
git checkout -b 2785 branch-heads/2785
./build/install-build-deps.sh
gcient sync --nohook --with_branch_heads --with_tags
# 注意:这里是[.空格build/*]
export GYP_GENERATORS=ninja
. build/android/envsetup.sh
~/chromium$ echo "{ 'GYP_DEFINES': 'OS=android', }" > chromium.gyp_env
# 生成out/下面必要资源文件
android_gyp
gclient runhooks
# 生成对应的apk版本
ninja -C out/Release chrome_public_apk
ninja -C out/Release content_shell_apk
ninja -C out/Release android_webview_apk
# 设置网络
sudo vim /etc/network/interfaces
auto wlan0
iface wlan0 inet static
address 192.168.1.151
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
sudo vim /etc/resolv.conf
#nameserver 127.0.0.1
nameserver 202.96.209.133
nameserver 202.96.209.5
nameserver 8.8.8.8
nameserver 8.8.4.4
如需要安装google的公钥,运行如下语句。
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
运行 linux的依赖或者android依赖时,如果在比较新的ubuntu版本上面编译老版本的chromium/webview,需要增加当前新ubuntu系统的支持,比如:加上 bionic
.
vim ./build/install-build-deps.sh
...
supported_releases="(precise|trusty|utopic|vivid|wily|xenial|yakkety|jessie|bionic)
...
遇到 google_play_services 相关的问题,只要手动下载以下即可。
# 在src目录下运行如下语句,下载 google_play_services
python build/android/play_services/update.py download
# 下载sdk
python build/android/play_services/update.py sdk
# 编译老版本chromium时,可能会用到python2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 200
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 100
sudo update-alternatives --config python
python --version
sudo apt-get install -y llvm clang
clang -v
# 设置 amd64,也就是x64
build/linux/sysroot_scripts/install-sysroot.py --arch=amd64
build/linux/sysroot_scripts/install-sysroot.py --arch=i386
build/linux/sysroot_scripts/install-sysroot.py --arch=arm
build/linux/sysroot_scripts/install-sysroot.py --arch=arm64
build/linux/sysroot_scripts/install-sysroot.py --arch=mips
Usage: install-sysroot.py [OPTIONS]
install-sysroot.py: error: option --arch: invalid choice: 'x64' (choose from 'arm', 'arm64', 'i386', 'amd64', 'mips')
build/linux/sysroot_scripts/install-sysroot.py
You much specify either --arch or --running-as-hook
gn gen out/Release_arm64 --args='target_os="android" target_cpu="arm64" 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_arm64 chrome_public_apk
ninja -C out/Release_arm64 content_shell_apk
ninja -C out/Release_arm64 android_webview_apk
gn gen out/Debug_arm64 --args='target_os="android" target_cpu="arm64" is_debug=true is_official_build=false 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/Debug_arm64 chrome_public_apk
ninja -C out/Debug_arm64 content_shell_apk
ninja -C out/Debug_arm64 android_webview_apk
gn gen out/Release_x64 --args='target_os="android" target_cpu="x64" 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_x64 chrome_public_apk
ninja -C out/Release_x64 content_shell_apk
ninja -C out/Release_x64 android_webview_apk
gn gen out/Release_x86 --args='target_os="android" target_cpu="x86" 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_x86 chrome_public_apk
ninja -C out/Release_x86 content_shell_apk
ninja -C out/Release_x86 android_webview_apk
gn gen out/Release_arm --args='target_os="android" target_cpu="arm" 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_arm chrome_public_apk
ninja -C out/Release_arm content_shell_apk
ninja -C out/Release_arm android_webview_apk
# 这个还没验证, https://blog.csdn.net/qq_21216109/article/details/113097090
# For L+ (21+) devices (if on N-P, see "Important Notes for N-P")
autoninja -C out/Default system_webview_apk
# For N-P (24-28) devices (not including TV/car devices)
autoninja -C out/Default monochrome_public_apk
# For Q+ (29+) devices
autoninja -C out/Default trichrome_webview_apk
# 下面这些可以直接编译
autoninja -C out/Release_arm64 system_webview_apk
autoninja -C out/Release_arm64 monochrome_public_apk
# 默认使用的是ndk24,所以不支持trichrome_webview_apk
autoninja -C out/Release_arm64 trichrome_webview_apk
编译后主要动态库
SystemWebView.apk
lib/armeabi-v7a/libwebviewchromium.so
lib/arm64-v8a/libwebviewchromium.so
ChromePublic.apk
lib/arm64-v8a/libchromium_android_linker.so
lib/arm64-v8a/crazy.libchrome.so
ContentShell.apk
lib/arm64-v8a/libosmesa.so
lib/arm64-v8a/libcontent_shell_content_view.so
AndroidWebView.apk
lib/arm64-v8a/libstandalonelibwebviewchromium.so
lib/arm64-v8a/libdrawgl.so
MonochromePublic
lib/arm64-v8a/libmonochrome.so
lib/armeabi-v7a/libmonochrome.so