Sunday, April 21, 2013

Android : How to build latest WebRTC revision for Android (on Linux) and run on device

WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities via simple Javascript APIs. It also has a android ndk project WebRTCDemo which can be used as application (.apk) on android device. But one thing I should mention that this demo client does not support peer-connection feature. So it can not connect with http://apprtc.appspot.com. If you need 
an android client that can connect http://apprtc.appspot.com then you need to check out 
libjingle project. I am going to post on this issue in near future.

The WebRTCDemo can be built on ubuntu if you go through the following steps (use terminal to execute command):

  • Download the latest Android SDK and NDK. edit ~/.bashrc to add the paths accordingly. 
export ANDROID_SDK="<path to your Android SDK directory>"
export ANDROID_NDK="<path to your Android NDK directory>"
export PATH="$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_NDK"
  • Download depottools and edit ~/.bashrc to add path.
  • source ~/.bashrc
  • install (sudo apt-get install...):
      g++ (>= 4.2)
      python (>= 2.4)
      libasound2-dev
      libpulse-dev
      libjpeg62-dev
      libxv-dev
      libgtk2.0-dev
      libexpat1-dev

    For 32-bit builds on a 64-bit system:
      lib32asound2-dev
      ia32-libs
  • create a folder where you can download source code from trunk and go to the folder from terminal.
  • gclient config https://webrtc.googlecode.com/svn/trunk
  • vim .gclient 
  • add this line ";target_os = ["android", "unix"]" to .gclient file.
  • gclient sync
  • cd trunk
  • source ./build/android/envsetup.sh
  • gclient runhooks 
  • sudo ./build/install-build-deps-android.sh
  • vim ./webrtc/video_engine/test/android/build_demo.py
  • [replace return 'source %s && %s' % (_ANDROID_ENV_SCRIPT, cmd) with return '/bin/bash -c "source %s" && %s' % (_ANDROID_ENV_SCRIPT, cmd)]
  • ninja -C out/Debug
  • You will find your build file (.apk file) in ./webrtc/video_engine/test/android/bin folder.
Here are the steps to run the application on android device:
  • run apk on both android devices.
  • configure remote ip address in settings tab on both android devices.(Note: as it does not support peer-connection so these devices need to know each other directly without any server interaction. So devices need to be in same network)
  • press StartCall button in Main tab on both android devices.