Android development is only supported on Linux.
Install prerequisite software
Create a working directory, enter it, and run:
$ fetch --nohooks webrtc_android $ gclient sync
This will fetch a regular WebRTC checkout with the Android-specific parts added. Notice that the Android specific parts like the Android SDK and NDK are quite large (~8 GB), so the total checkout size will be about 16 GB. The same checkout can be used for both Linux and Android development since you can generate your Ninja project files in different directories for each build config.
See Development for instructions on how to update the code, building etc.
Make sure your current working directory is src/ of your workspace. Then run:
$ gn gen out/Debug --args='target_os="android" target_cpu="arm"'
You can specify a directory of your own choice instead of
out/Debug, to enable managing multiple configurations in parallel.
$ autoninja -C out/Debug
(To list all available targets, run
autoninja -C out/Debug -t targets all.)
In order to use the Android SDK and NDK that is bundled in
third_party/android_tools, run this to get it included in your
$ . build/android/envsetup.sh
Then you'll have
adb and all the other Android tools in your
AppRTCMobile is an Android application using WebRTC Native APIs via JNI (JNI wrapper is documented here).
For instructions on how to build and run, see examples/androidapp/README.
Note: This is known to be broken at the moment. See bug: https://bugs.webrtc.org/9282
$ autoninja -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
Import the project in Android Studio. (Do not just open it.) The project is located in
out/Debug/gradle. If asked which SDK to use, choose to use Android Studio's SDK. When asked whether to use the Gradle wrapper, press “OK”.
webrtc > examples > AppRTCMobile is selected and press Run. AppRTCMobile should now start on the device.
If you do any changes to the C++ code, you have to compile the project using autoninja after the changes (see step 1).
Note: Only “arm” is supported as the target_cpu when using Android Studio. This still allows you to run the application on 64-bit ARM devices. x86-based devices are not supported right now.
To build APKs with the WebRTC native tests, follow these instructions.
Ensure you have an Android device set in Developer mode connected via USB.
Compile unit tests and/or instrumentation tests:
$ autoninja -C out/Debug android_instrumentation_test_apk $ autoninja -C out/Debug rtc_unittests
out/Debug/bin. To run instrumentation tests:
$ out/Debug/bin/run_android_instrumentation_test_apk -v
To run unit tests:
$ out/Debug/bin/run_rtc_unittests -v
Show verbose output with
-v and filter tests with
--gtest-filter=SomeTest.*. For example:
$ out/Debug/bin/run_android_instrumentation_test_apk -v \ --gtest_filter=VideoFrameBufferTest.*
For a full list of command line arguments, use
If want to run Release builds instead; pass
is_debug=false to GN (and preferably generate the projects files into a directory like
out/Release). Then use the scripts generated in