본문 바로가기

프로그래밍/WebRTC

WebRTC native build

 

https://webrtc.org/native-code/

 

WebRTC Native Code | WebRTC

 

webrtc.org


공통

git
openJDK : openjdk-7-jdk
python 2.7 : python2.7

 

 

depot tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
   fetch : gclient 랩퍼
   gclient : checkout 도구
   git_cl : 코드리뷰 도구
   roll-dep : gclient 기반 관리 도구
   gn
   ninja
   
   gclient or gclient.bat을 실행하면 git, python등 필요한 패키지들이 설치됨

 

 

depot_tools 경로 추가

export PATH=$PATH:/폴더/depot_tools

 

프로젝트 생성

gn gen output --args='target_os="ios" target_cpu="arm64"'

 

프로젝트의 전체 args 목록 확인

gn args --list output-path

 


iOS

cocoapods

source 'https://github.com/CocoaPods/Specs.git'
target 'YOUR_APPLICATION_TARGET_NAME_HERE' do
   platform:ios, '9.0' // 참고: 최근버전은 spec 파일에 platform 버전이 10.0 으로 되어 있음

   pod 'GoogleWebRTC'
end

소스 직접 빌드

소스 가져와 동기화

mkdir webrtc
cd webrtc
fetch --nohooks webrtc_ios
gclient sync

 

작업을 위해 별도 브랜치 사용 권장

(특정 버전의 브랜치 변경시에는 내부 도구들과 위치가 변경되므로 gclient sync 를 해주어야 한다.) 

cd src
git checkout -b my_webrtc_branch
gclient sync

 

 

GN을 사용해 ninja 프로젝트 생성

지원 플랫폼 : arm, arm64, x86, x64

참고 : DEFAULT_ARCHS = ENABLED_ARCH (src/tools_webrtc/ios/build.ios_libs.py)

cd src

// arm64
gn gen out/arm64/Debug --args='is_debug=true target_os="ios" target_cpu="arm64"'

// 시뮬레이터
gn gen out/simul/Debug --args='target_os="ios" target_cpu="x64"'

// mac
gn gen out/mac/Debug --args='target_os="mac" target_cpu="x64"'

 

주요 파라미터

target_os="ios"|"mac"
target_cpu="arm64"|"arm"|"x64"|"x86"

ios_deployment_target="10.0"
ios_enable_code_signing=false

use_xcode_clan=true
treat_warnings_as_errors=false

enable_ios_bitcode=false
enable_dsyms=true 
enable_stripping=true

is_debug=true
is_component_build=false

rtc_user_h264=false
rtc_libvpx_build_vp9=false
rtc_include_tests=false
rtc_build_examples=false

signing 제외 : ios_enable_code_signing=false
테스트 타겟 에러 : rtc_include_tests=false


 

 

xcode용 프로젝트 생성

컴파일은 ninja를 사용해야 하지만 소스 분석이나 수정을 위한 xcode 프로젝트 생성

gn gen out/arm64 --args='target_os="ios" target_cpu="arm64" --ide=xcode
open -a Xcode.app out/arm64/all.xcworkspace

 

 

컴파일

ninja -C out/arm64 타겟명

ios 라이브러리용 타겟 :  framework_objc
static 빌드 : webrtc

 

그외 정의된 타겟 리스트 보기

gn ls out/arm64

 

 

 

컴파일 도구
파이썬 스크립트를 사용해 컴파일 : arm64, arm, x64, x86 이 기본으로 설정되므로 모두 빌드되고 fat framework를 생성해 준다.
python src/tools_webrtc/ios/build_ios_libs.py --bitcode

파라미터 : 
--build_config [debug|release]
--output-dir [out_ios_libs]
--arch [arm64|arm|x64|x86]
--clean
--bitcode

* m93(4577) 부터 xcframework 로 빌드되도록 스크립트 수정됨.

 

arm64 환경에서 빌드

로제타 설치
터미널 or iTerm 복제
복제한 터미널을 Rosetta를 사용하여 열기 체크
해당 터미널 실행 후 /usr/local/lib 폴더 생성 - webrtc 빌드시 path 에러 나므로 빈 디렉토리가 생성되어 있어야함
그외는 동일


* iOS 이외의 항목은 빌드 방식이나 환경이 현재 상황과 다를 수 있음(현 ios 개발자이다 보니...-_-;;)

안드로이드

gradle

build.gradle
implementation 'org.webrtc:google-webrtc:1.0.+'

 

소스 직접 빌드

안드로이드용 라이브러리 빌드는 리눅스 환경에서만 빌드가 가능 : ubuntu 18.04 사용
안드로이드 구성요소 설치시 OpenJDK 8 요구

$ sudo apt install openjdk-8-jdk
$ sudo update-alternatives --config java

문제가 있으면 jdk를 날리고 다시 설치 :)
$ sudo apt autoremove openjdk-12-jdk
$ sudo apt purge openjdk*

JAVA_HOME
$ export JAVA_HOME=/usr/lib/jvm/java8-openjdk-amd64

pkg-config 설치
$ sudo apt install pkg-config

 

소스 가져와 동기화
안드로이드 sdk, ndk를 포함하므로 상당한 용량이 다운로드됨. 17기가 정도..

fetch --nohooks webrtc_android
gclient sync

 

 

소스는 동일하고, 빌드를 위한 환경이 타겟에 따라 변경됨
.gclient 파일에 따라 gclient sync 명령으로 빌드 플랫폼 변경 가능
생성된 .gclient 파일

solutions = [
  {
    "url": "https://webrtc.googlesource.com/src.git",
    "managed": False,
    "name": "src",
    "deps_file": "DEPS",
    "custom_deps": {},
  },
]
target_os = ["android", "unix"]

 

target_os 를 ["ios", "mac"] 으로 변경하고, gclient sync 해주면 ios 빌드 환경으로 변경됨.

 

 

브랜치변경
기본은 master 브랜치이며, 필요에 따라 브랜치를 변경할 수 있음

git branch -r
git checkout branch-heads/m번호
git checkout -b my_webrtc_branch
gclient sync

 

빌드를 위한 구성요소 설치

cd src
sudo ./build/install-build-deps.sh
sudo ./build/install-build-deps-android.sh

--no-chromeos-fonts : 폰트제외

 

메뉴얼빌드
GN을 사용해 ninja 프로젝트 생성

gn gen out/Debug --args='target_os="andorid" target_cpu="arm"'


   arm32 : target_cpu="arm"
   arm64 : target_cpu="arm64"
   x86 : target_cpu="x86"
   x64 : target_cpu="x64"

 

컴파일

ninja -C out/Debug AppRTCMobile

 

 

안드로이드 스튜디오 프로젝트 생성

AppRTCMobile 컴파일 : ninja -C out/Debug AppRTCMobile

./build/android/gradle/generate_gradle.py \
   --output-directory $PWD/out/Debug \
   --target "//examples:AppRTCMobile" \
   --use-gradle-process-resources \
   --split-projects \
   --canary

 

안드로이드 프로젝트
libs 폴더에 jar 파일 복사
타겟별로 폴더 생성해 so 넣기
   jniLibs/arm640v8a
   jniLibs/armeabi-v7a
   jniLibs/x86
   jniLibs/x86_64

안드로이드 SDK/NDK
번들로 제공된 안드로이드 SDK/NDK를 사용해 빌드하려면 third_party/android_tools 의 도구를 사용하기 위한 안드로이드 환경 설정

./build/android/envsetup.sh

 


AAR 빌드 도구

모든 so, jar를 빌드해 libwebrtc.aar 로 생성해주는 스크립트 : 일반적인 경우 이 스크립트로 생성된 aar 파일을 프로젝트에 추가해 사용

tools_webrtc/android/build_aar.py --build-dir ./out/aar --output ./out/libwebrtc.aar

 


윈도우

vs2017
   Common Tools for Visual C++ 2017
   Microsoft Foundation Classes for C++
   Windows XP Support for C++
   Windows 10 SDK , Debugging Tools for Windows

 

환경변수 등록
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GYP_MSVS_VERSION=2017
set GYP_GENERATORS=msvs-ninja,ninja
set GYP_DEFINES="target_arch=x64 component=shared_library"
set GYP_MSVS_OVERRIDE_PATH="VS2017 위치"

 

소스 가져와 동기화
fetch --nohooks webrtc
gclint sync

 

프로젝트 생성 및 컴파일
gn gen out/Debug args="fatal_linker_warning=false"

ninja -C out/Debug


기타

GN으로 프로젝트 생성시 다양한 인자 지원
   use_custom_libcxx=false
   rtc_use_h264=true
   ffmpeg_branding=\"Chrome\"
   rtc_include_tests=false
   rtc_include_pulse_audio=false
   use_sysroot=false
   is_clang=false
   is_component_build=false
   treat_warnings_as_errors=false
   fatal_linker_warning=false
   is_debug=false