注1:本文档适用于webrtc和webrtc-android源码的下载和编译;
注2:下载编译所使用的操作系统为Ubuntu 14.04.3 LTS;
Chromium和Chromium OS统一使用一个叫做depot_tools的工具的对其源码进行checkout的管理(这有点类似于Android使用repo工具对其源码进行管理一样),作为Chromium其中一个子模块的webrtc而言,也是使用这个工具对其代码进行checkout。这个depot_rools包里面包含了gclient、gcl、git-cl、repo等工具。
下载depot_tools工具包并放到标准路径PATH上:
首先确保Linux上安装了Git 2.2.1以上版本,以及Python 2.7以上版本;
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
修改HOME目录中的.bashrc文件,在最后增加:PATH="~/bin/depot_tools:$PATH",注意一定要把depot_tools的位置放在PATH的最前面;
参考:https://dev.chromium.org/developers/how-tos/install-depot-tools
下载webrtc-native代码及编译流程(首先要先按照以上步骤下载depot_tools):
mkdir webrtc-checkout
cd webrtc-checkout
fetch --nohooks webrtc
gclient sync//代码下载过程中如果发生中断,使用gclient sync同步就可以了
cd src/
./build/install-build-deps.sh(只需要在第一次gclient sync以后执行一次)
gn gen out/Default
ninja -C out/Default
gn clean out/Default
下载webrtc-android代码及编译流程(首先要先按照以上步骤下载depot_tools ):
mkdir webrtc-android
cd webrtc-android
fetch --nohooks webrtc_android
gclient sync//代码下载过程中如果发生中断,使用gclient sync同步就可以了
cd src/
./build/install-build-deps.sh(只需要在第一次gclient sync以后执行一次)
gn gen out/Debug --args='target_os="android" target_cpu="arm"'
ninja -C out/Debug
gn clean out/Debug
编译和安装AppRTCMobile :
ninja -C out/Default AppRTCMobile
adb install -r out/Default/apks/AppRTCMobile.apk
WebRTC代码后期更新的三种方式(在src目录下):
当前代码在某个分支下进行维护,使用git pull可以拉取远程仓库的最新更新;
当前代码不在分支下,使用git fetch取下来最新的git仓库更新;
需要定期更新依赖或者其他第三方库,使用gclient sync命令;
附录:
1.webrtc-android版本下载及编译过程中存在play_services不存在的问题
问题描述:
下载完成后执行:gn gen out/Debug --args='target_os="android" target_cpu="arm"'命令出现以下打印错误:
pavel@ubuntu-han:~/webrtc-android/src$ gn gen out/Debug --args='target_os="android" target_cpu="arm"'
ERROR at //build/config/android/rules.gni:2739:9: Script returned non-zero exit code. exec_script("//build/android/gyp/aar.py",
^----------
Current dir: /home/pavel/webrtc-android/src/out/Debug/
Command: python -- /home/pavel/webrtc-android/src/build/android/gyp/aar.py --input-file ../../third_party/android_tools/sdk/extras/google/m2repository/com/google/android/gms/play-services-basement/10.2.0/play-services-basement-10.2.0.aar --list
Returned 1.
stderr:
Traceback (most recent call last):
File "/home/pavel/webrtc-android/src/build/android/gyp/aar.py", line 114, in
sys.exit(main())
File "/home/pavel/webrtc-android/src/build/android/gyp/aar.py", line 81, in main
with zipfile.ZipFile(aar_file) as z:
File "/usr/lib/python2.7/zipfile.py", line 701, in __init__
self.fp = open(file, modeDict[mode])
IOError: [Errno 2] No such file or directory: '../../third_party/android_tools/sdk/extras/google/m2repository/com/google/android/gms/play-services-basement/10.2.0/play-services-basement-10.2.0.aar'
See //third_party/android_tools/BUILD.gn:191:1: whence it was called.
android_aar_prebuilt("google_play_services_basement_java") {
^-----------------------------------------------------------
See //webrtc/system_wrappers/BUILD.gn:155:7: which caused the file to be included. "//third_party/android_tools:cpu_features",
^-----------------------------------------
解决办法:
通过对该问题进行跟踪和查询,应该是在下载play services框架的时候有一个license需要yes才可以,执行以下命令重新启动play services的下载并在下载的过程中许可license:
./src/build/android/play_services/update.py download
2.webrtc-android版本编译出现的jni问题
问题描述:
pavel@ubuntu-han:~/webrtc-android/src$ ninja -C out/Debug/
ninja: Entering directory `out/Debug/'
[3/7329] ACTION //base:android_runtime_jni_headers__jni_Runtime(//build/toolchain/android:android_arm)
FAILED: gen/android_runtime_jni_headers/base/jni/Runtime_jni.h
python ../../base/android/jni_generator/jni_generator.py --depfile gen/base/android_runtime_jni_headers__jni_Runtime.d --jar_file ../../third_party/android_tools/sdk/platforms/android-24/android.jar --input_file java/lang/Runtime.class --optimize_generation=1 --ptr_type=long --output_dir gen/android_runtime_jni_headers/base/jni --includes ../../../../../../base/android/jni_generator/jni_generator_helper.h --native_exports_optional
Traceback (most recent call last):
File "../../base/android/jni_generator/jni_generator.py", line 1418, in
sys.exit(main(sys.argv))
File "../../base/android/jni_generator/jni_generator.py", line 1411, in main
GenerateJNIHeader(input_file, output_file, options)
File "../../base/android/jni_generator/jni_generator.py", line 1314, in GenerateJNIHeader
jni_from_javap = JNIFromJavaP.CreateFromClass(input_file, options)
File "../../base/android/jni_generator/jni_generator.py", line 663, in CreateFromClass
stderr=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
[4/7329] CXX obj/base/base_paths/base_paths_android.o
解决办法:
出现以上问题是由于当前系统中缺少一些编译webrtc-android的组件,需要调用以下两个脚本在当前系统中安装必要的组件即可:
./build/install-build-deps.sh
./build/install-build-deps-android.sh