You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. # WebRTC Android development
  2. ## Prebuilt libraries
  3. The easiest way to get started is using the [official prebuilt libraries][prebuilt-libraries]
  4. available at JCenter. These libraries are compiled from the tip-of-tree and are
  5. meant for development purposes only.
  6. On Android Studio 3 add to your dependencies:
  7. ```
  8. implementation 'org.webrtc:google-webrtc:1.0.+'
  9. ```
  10. On Android Studio 2 add to your dependencies:
  11. ```
  12. compile 'org.webrtc:google-webrtc:1.0.+'
  13. ```
  14. The version of the library is `1.0.<Cr-Commit-Position>`. The hash of the commit
  15. can be found in the .pom-file. The third party licenses can be found in the
  16. THIRD_PARTY_LICENSES.md file next to the .aar-file.
  17. ## Getting the Code
  18. Android development is only supported on Linux.
  19. 1. Install [prerequisite software][webrtc-prerequisite-sw]
  20. 2. Create a working directory, enter it, and run:
  21. ```
  22. $ fetch --nohooks webrtc_android
  23. $ gclient sync
  24. ```
  25. This will fetch a regular WebRTC checkout with the Android-specific parts
  26. added. Notice that the Android specific parts like the Android SDK and NDK are
  27. quite large (~8 GB), so the total checkout size will be about 16 GB.
  28. The same checkout can be used for both Linux and Android development since you
  29. can generate your [Ninja][ninja] project files in different directories for each
  30. build config.
  31. See [Development][webrtc-development] for instructions on how to update
  32. the code, building etc.
  33. ## Compiling
  34. 1. Generate projects using GN.
  35. Make sure your current working directory is src/ of your workspace.
  36. Then run:
  37. ```
  38. $ gn gen out/Debug --args='target_os="android" target_cpu="arm"'
  39. ```
  40. You can specify a directory of your own choice instead of `out/Debug`,
  41. to enable managing multiple configurations in parallel.
  42. * To build for ARM64: use `target_cpu="arm64"`
  43. * To build for 32-bit x86: use `target_cpu="x86"`
  44. * To build for 64-bit x64: use `target_cpu="x64"`
  45. 2. Compile using:
  46. ```
  47. $ ninja -C out/Debug
  48. ```
  49. ## Using the Bundled Android SDK/NDK
  50. In order to use the Android SDK and NDK that is bundled in
  51. `third_party/android_tools`, run this to get it included in your `PATH` (from
  52. `src/`):
  53. ```
  54. $ . build/android/envsetup.sh
  55. ```
  56. Then you'll have `adb` and all the other Android tools in your `PATH`.
  57. ## Running the AppRTCMobile App
  58. AppRTCMobile is an Android application using WebRTC Native APIs via JNI (JNI
  59. wrapper is documented [here][webrtc-jni-doc]).
  60. For instructions on how to build and run, see
  61. [examples/androidapp/README][apprtc-doc].
  62. ## Using Android Studio
  63. *Note: This is known to be broken at the moment. See bug:
  64. https://bugs.webrtc.org/9282*
  65. 1. Build the project normally (out/Debug should be the directory you used when
  66. generating the build files using GN):
  67. ```
  68. $ ninja -C out/Debug AppRTCMobile
  69. ```
  70. 2. Generate the project files:
  71. ```
  72. $ build/android/gradle/generate_gradle.py --output-directory $PWD/out/Debug \
  73. --target "//examples:AppRTCMobile" --use-gradle-process-resources \
  74. --split-projects --canary
  75. ```
  76. 3. *Import* the project in Android Studio. (Do not just open it.) The project
  77. is located in `out/Debug/gradle`. If asked which SDK to use, choose to use
  78. Android Studio's SDK. When asked whether to use the Gradle wrapper, press
  79. "OK".
  80. 4. Ensure target `webrtc > examples > AppRTCMobile` is selected and press Run.
  81. AppRTCMobile should now start on the device.
  82. If you do any changes to the C++ code, you have to compile the project using
  83. ninja after the changes (see step 1).
  84. *Note: Only "arm" is supported as the target_cpu when using Android Studio. This
  85. still allows you to run the application on 64-bit ARM devices. x86-based devices
  86. are not supported right now.*
  87. ## Running WebRTC Native Tests on an Android Device
  88. To build APKs with the WebRTC native tests, follow these instructions.
  89. 1. Ensure you have an Android device set in Developer mode connected via
  90. USB.
  91. 2. Compile as described in the section above.
  92. 3. To see which tests are available: look in `out/Debug/bin`.
  93. 4. Run a test on your device:
  94. ```
  95. $ out/Debug/bin/run_modules_unittests
  96. ```
  97. 5. If you want to limit to a subset of tests, use the `--gtest_filter flag`, e.g.
  98. ```
  99. $ out/Debug/bin/run_modules_unittests \
  100. --gtest_filter=RtpRtcpAPITest.SSRC:RtpRtcpRtcpTest.*
  101. ```
  102. 6. **NOTICE:** The first time you run a test, you must accept a dialog on
  103. the device!
  104. If want to run Release builds instead; pass `is_debug=false` to GN (and
  105. preferably generate the projects files into a directory like `out/Release`).
  106. Then use the scripts generated in `out/Release/bin` instead.
  107. ## Running WebRTC Instrumentation Tests on an Android Device
  108. The instrumentation tests (like AppRTCMobileTest and
  109. libjingle_peerconnection_android_unittest) gets scripts generated in the same
  110. location as the native tests described in the previous section.
  111. [webrtc-prerequitite-sw]: https://webrtc.googlesource.com/src/+/refs/heads/master/docs/native-code/development/prerequisite-sw/index.md
  112. [webrtc-jni-doc]: https://webrtc.googlesource.com/src/+/master/sdk/android/README
  113. [apprtc-doc]: https://webrtc.googlesource.com/src/+/master/examples/androidapp/README
  114. [ninja]: https://ninja-build.org/
  115. [prebuilt-libraries]: https://bintray.com/google/webrtc/google-webrtc
  116. [webrtc-development]: https://webrtc.googlesource.com/src/+/refs/heads/master/docs/native-code/development/index.md