Mac下载并编译webrtc,安装模拟器和真机Demo

以下步骤需要在墙外(vpn的速度不要太慢): 

一、下载代码

1.  下载depot_tools  

$  svn co  http://src.chromium.org/svn/trunk/tools/depot_tools

2. 打开source .bash_profile 添加depot_tools路径到系统目录 export PATH=$PATH:/Users/mac/depot_tools

3.

$ cd /Users/mac/depot_tools
$ gclient config http://webrtc.googlecode.com/svn/trunk

4.

$ gclient sync --force

     在这一步block了很久,遇到了以下错误:

 Error: Command download_from_google_storage --directory --recursive --num_threads=10 --no_auth --bucket chromium-webrtc-resources trunk/resources returned non-zero exit status 1 in /Users/xxx/work/webrtc/depot_tools
Hook 'download_from_google_storage --directory --recursive --num_threads=10 --no_auth --bucket chromium-webrtc-resources trunk/resources' took 20.05 secs

 最后在google code下找到了解决的办法:

(https://code.google.com/p/webrtc/issues/detail?id=2811)     

找到 trunk/DEPS 下的这几行代码并把它注释掉
  {
    # Download test resources, i.e. video and audio files from Google Storage.
    "pattern": "\\.sha1",
    "action": ["download_from_google_storage",
               "--directory",
               "--recursive",
               "--num_threads=10",
               "--no_auth",
               "--bucket", "chromium-webrtc-resources",
               Var("root_dir") + "/resources"],
  },

5. $gclient runhooks --force

6. 进入 trunk目录,打开all.xcodeproj/

扫描二维码关注公众号,回复: 623536 查看本文章

 

二、编译源码:

根据 trunk/talk/app/webrtc/objc/README 说明,编译源码。

1.找到WebRTC目录下.gclient 文件的内容,添加 target_os = ['ios', 'mac']  

2. 在.gclient下添加后,在终端WebRTC路径下,重新执行:

 gclient sync

3.1. 编译为MAC版本

进入trunk路径,执行如下命令

export GYP_DEFINES="build_with_libjingle=1 build_with_chromium=0 libjingle_objc=1"
export GYP_GENERATORS="xcode"    

最后找到trunk路径下的all.xcodeproj,用xcode打开就可以了。

3.2. 编译为iOS模拟器版本

export GYP_DEFINES="$GYP_DEFINES OS=ios target_arch=ia32"
  export GYP_GENERATOR_FLAGS="$GYP_GENERATOR_FLAGS output_dir=out_sim"
  export GYP_CROSSCOMPILE=1
  gclient runhooks 
  ninja -C out_sim/Debug iossim AppRTCDemo 

执行了这些后,会在trunk/out_sim/Debug 路径下会产生一个文件 AppRTCDemo.app

执行下列命令即可启动demo

./out_sim/Debug/iossim out_sim/Debug/AppRTCDemo.app

执行  gclient runhooks 遇到这个错误:

AssertionError: Multiple codesigning fingerprints for identity: iPhone Developer

参考:http://ninjanetic.com/how-to-get-started-with-webrtc-and-ios-without-wasting-10-hours-of-your-life/

在文件 : trunk/tools/gyp/pylib/gyp/xcode_emulation.py and at lines 832-833 comment the following line :
#assert identity not in cache or fingerprint == cache[identity], (

#”Multiple codesigning fingerprints for identity: %s” % identity) 

解决问题。

3.3 编译为iOS真机版本

a. 安装homebrew

    http://chriszeng87.iteye.com/blog/2077674

b. 

brew install ideviceinstaller --HEAD

    (时间较长)

c.  

touch makeall-iosdevice.sh
chmod +x makeall-iosdevice.sh

把以下内容复制到你刚刚创建的文件中 

function fetch() {
echo "-- fetching webrtc"
gclient config http://webrtc.googlecode.com/svn/trunk/
echo "target_os = ['mac']" >> .gclient
gclient sync

sed -i "" '$d' .gclient
echo "target_os = ['ios', 'mac']" >> .gclient
gclient sync
echo "-- webrtc has been sucessfully fetched"

}

function wrbase() {
export GYP_DEFINES="build_with_libjinglth_chromium=0 libjingle_objc=1"
export GYP_GENERATORS="ninja"
}

function wrios() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=ios target_arch=armv7"
export GYP_GENERATOR_FLAGS="$GYP_GENERATOR_FLAGS output_dir=out_ios"
export GYP_CROSSCOMPILE=1
}

function wrmac() {
wrbase
export GYP_DEFINES="$GYP_DEFINES OS=mac target_arch=x64"
export GYP_GENERATOR_FLAGS="$GYP_GENERATOR_FLAGS output_dir=out_mac"
}

function buildios() {
echo "-- building webrtc ios"
pushd trunk
wrios && gclient runhooks && ninja -C out_ios/Debug-iphoneos AppRTCDemo
popd
echo "-- webrtc has been sucessfully built"
}

function launch() {
echo "-- launching on device"
ideviceinstaller -i trunk/out_ios/Debug-iphoneos/AppRTCDemo.app
echo "-- launch complete"
}

function fail() {
echo "*** webrtc build failed"
exit 1
}

#fetch || fail
wrios || fail
buildios || fail
launch || fail

最后 

./makeall-iosdevice.sh

 大功告成。

 

以上参考了:

1. http://www.cnblogs.com/leehongee/p/3383266.html

2. http://blog.csdn.net/qs_csu/article/details/17416003

3. http://ninjanetic.com/how-to-get-started-with-webrtc-and-ios-without-wasting-10-hours-of-your-life/

 

猜你喜欢

转载自chriszeng87.iteye.com/blog/2077119