android webrtc构建过程
How To Compile Native WebRTC Library from Source for Android
source: webrtc.org
In this article I assume you use Linux and understand about webrtc, and android development, please consider reading those before continuing if you feel not comfortable.
abdularis/libwebrtc-android
Contribute to abdularis/libwebrtc-android development by creating an account on GitHub.
github.com
Install Prerequisite (Chromium depot_tools)
First we need to setup all tools we need, which is depot_tools, it includes custom git binary, ninja build tools, gclient, gn, fetch etc.
It is quite easy, clone the repository from https://chromium.googlesource.com/chromium/tools/depot_tools.git then add the local cloned repository into the PATH environment variables.
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
add into PATH environment variables, so the binary included in the repository would be available in the terminal (command line).
export PATH=$PATH:/path/to/depot_tools
head over to this link for more information.
Getting The Source Code
Use fetch command to get the webrtc source code for android, before done this you may want to go over another or new directory to place the source code in.
fetch --nohooks webrtc_android
Then.
gclient sync
After that go to webrtc_android/src/ directory, which is just created by the command above.
The process may take long because it require the android build chain tools, it is around 16GB checkout.
Then you need to install all the dependency needed to build the source code.
./build/install-build-deps.sh
Also make sure you have OpenJDK installed and configured properly on your machine (I used version OpenJDK 1.8)
Before compiling the code you can checkout to particular git branch to go into different available webrtc version, to list all the branch use this git command.
git branch -r
Output is something like below
正在上传…重新上传取消
output: git branch -r
Like the above result you can checkout to the latest version which is m74 by.
git checkout branch-heads/m74
To check what is your current branch type in.
git branch
正在上传…重新上传取消
正在上传…重新上传取消
output: git branch
Compilation
There are two ways I have tried out to compile webrtc for android, here are those two starting with the most easy way (Thanks to great developers & contributors of webrtc).
Using AAR build tools
tools_webrtc/android/build_aar.py
It would compile the source code for all supported cpu type such as arm64-v8a, armeabi-v7a, x86, x86_64 and then package these native libraries and .jar library into .aar file.
转存失败重新上传取消
转存失败重新上传取消
output: compilation
.AAR file resides in your current working directory or src/ directory with default name libwebrtc.aar
Finally you can use the aar library in your project, or publish it into maven repository.
Manual Compilation
Manually compile the source code for each particular cpu type.
gn gen out/Debug --args='target_os="android" target_cpu="arm"'
for release
gn gen out/Release --args='is_debug=false is_component_build=false rtc_include_tests=false target_os="android" target_cpu="arm"'
the output is in the out/Debug or out/Release (directory name is arbitrary), target_cpu can be arm64, x86 or x64.
begin compiling with ninja (output directory out/Debug or out/Release as explain above).
ninja -C out/Debug
compilation may take long depending on how powerful your machine. output of compilation is in the out/Debug or out/Release directory, native .sofile is in the lib.unstripped/, and the java .jar library is lib.java/ directory.
native .so library is unstripped you can strip to minimize file size using strip tools for particular cpu type such tool is located in webrtc_android/src/third_party/android_ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip (for x64 binary .so).
With manual compilation you also need to package all these library into .aar manually.
Manually compiling from the source code is quite challenging and tedious in my opinion and fortunately thanks to webrtc developers/contributors who made the build script for packaging into .aar library much more easier, for more information visit http://webrtc.github.io/webrtc-org/native-code/android/.
google原文:
Android
Show Contents
Prebuilt libraries
The easiest way to get started is using the official prebuilt libraries available at JCenter. These libraries are compiled from the tip-of-tree and are meant for development purposes only.
On Android Studio 3 add to your dependencies:
implementation 'org.webrtc:google-webrtc:1.0.+'
On Android Studio 2 add to your dependencies:
compile 'org.webrtc:google-webrtc:1.0.+'
The version of the library is 1.0.
. The hash of the commit can be found in the .pom-file. The third party licenses can be found in the THIRD_PARTY_LICENSES.md file next to the .aar-file.
Getting the Code
Android development is only supported on Linux.
-
Install prerequisite software
-
Create a working directory, enter it, and run:
fetch --nohooks webrtc_androidgclient 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.
Compiling
-
Generate projects using GN.
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.- To build for ARM64: use
target_cpu="arm64"
- To build for 32-bit x86: use
target_cpu="x86"
- To build for 64-bit x64: use
target_cpu="x64"
- To build for ARM64: use
-
Compile using:
ninja -C out/Debug
Using the Bundled Android SDK/NDK
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 PATH
(from src/
):
. build/android/envsetup.sh
Then you’ll have adb
and all the other Android tools in your PATH
.
Running the AppRTCMobile App
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.
Using Android Studio
Note: This is known to be broken at the moment. See bug: https://bugs.webrtc.org/9282
-
Build the project normally (out/Debug should be the directory you used when generating the build files using GN):
ninja -C out/Debug AppRTCMobile
-
Generate the project files:
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”. -
Ensure target
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 ninja 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.
Running WebRTC Native Tests on an Android Device
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 as described in the section above.
-
To see which tests are available: look in
out/Debug/bin
. -
Run a test on your device:
out/Debug/bin/run_modules_unittests
-
If you want to limit to a subset of tests, use the
--gtest_filter flag
, e.g.out/Debug/bin/run_modules_unittests \--gtest_filter=RtpRtcpAPITest.SSRC:RtpRtcpRtcpTest.*
-
NOTICE: The first time you run a test, you must accept a dialog on the device!
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 out/Release/bin
instead.
Running WebRTC Instrumentation Tests on an Android Device
The instrumentation tests (like AppRTCMobileTest and libjingle_peerconnection_android_unittest) gets scripts generated in the same location as the native tests described in the previous section.
更多相关文章
- Android 使用AsyncHttpClient文件上传与下载
- Android使用ksoap2调用C#中的webservice实现图像上传
- android之调用webservice 实现图片上传
- 如何上传应用软件到 Android Market集市网站
- android之调用webservice 实现图片上传下载
- Android上传文件,客户端+服务器源码