This document describes how to quickly integrate the Tencent Cloud TRTC SDK for Android into your project in the following steps.
You can use Gradle to automatically load the AAR file or manually download the AAR file and import it into your project.
The TRTC SDK has been released to the mavenCentral repository, and you can configure Gradle to download updates automatically.
Simply use Android Studio to open the project that needs to be integrated with the SDK (TRTCScenesDemo is used as an example in this document), and then modify the app/build.gradle
file in three simple steps to complete SDK integration:
dependencies
.Run the following command to use com.android.tools.build:gradle v3.x:
dependencies {
implementation 'com.tencent.liteav:LiteAVSDK_TRTC:latest.release'
}
Run the following command if you use the 2.x version of com.android.tools.build:gradle.
dependencies {
compile 'com.tencent.liteav:LiteAVSDK_TRTC:latest.release'
}
defaultConfig
, specify the CPU architecture to be used by your application.defaultConfig {
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
Note:Currently, the TRTC SDK supports armeabi-v7a, and arm64-v8a.
If you have difficulty accessing mavenCentral, you can manually download the SDK and integrate it into your project.
build.gradle
under the project's root directory and specify a local path for the repository.app/build.gradle
to import the AAR file.defaultConfig
of app/build.gradle
, specify the CPU architecture to be used by your application.defaultConfig {
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
Note:Currently, the TRTC SDK supports armeabi-v7a, and arm64-v8a.
If you do not want to import the AAR library, you can also integrate TRTC SDK by importing JAR and SO libraries.
SDK/LiteAVSDK_TRTC_xxx.zip
(xxx indicates the version number of TRTC SDK).libs
directory that contains a JAR file and several SO folders.armeabi-v7a
, and arm64-v8a
folders to the app/libs
directory.app/build.gradle
.app/build.gradle
.sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
6. In defaultConfig
of app/build.gradle
, specify the CPU architecture to be used by your application.
defaultConfig {
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
Note:Currently, the TRTC SDK supports armeabi-v7a, and arm64-v8a.
Configure application permissions in AndroidManifest.xml
. The TRTC SDK requires the following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Note:Do not set
android:hardwareAccelerated="false"
; otherwise, the video stream of the remote user cannot be rendered after hardware acceleration is disabled.
In the proguard-rules.pro
file, add the classes related to the TRTC SDK to the "do not obfuscate" list:
-keep class com.tencent.** { *; }
Add the following code to app/build.gradle
:
packagingOptions {
doNotStrip "*/armeabi-v7a/libYTCommon.so"
doNotStrip "*/x86/libYTCommon.so"
doNotStrip "*/arm64-v8a/libYTCommon.so"
}
If you prefer to use C++ APIs instead of Java for development, you can perform this step. If you only use Java to call the TRTC SDK, please skip this step.
First, you need to integrate the TRTC SDK by importing JAR and SO libraries as instructed above.
Copy the C++ header file in the SDK to the project (path: SDK/LiteAVSDK_TRTC_xxx/libs/include
) and configure the include
folder path and dynamic link to the SO library in CMakeLists.txt
.
cmake_minimum_required(VERSION 3.6)
# Configure the C++ API header file path
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include # Copied from `SDK/LiteAVSDK_TRTC_xxx/libs/include`
)
add_library(
native-lib
SHARED
native-lib.cpp)
# Configure the path of the `libliteavsdk.so` dynamic library
add_library(libliteavsdk SHARED IMPORTED)
set_target_properties(libliteavsdk PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${ANDROID_ABI}/libliteavsdk.so)
find_library(
log-lib
log)
# Configure the dynamic link as `libliteavsdk.so`
target_link_libraries(
native-lib
libliteavsdk
${log-lib})
Use the namespace: the methods and types of cross-platform C++ APIs are defined in the trtc
namespace. To simplify your code, you are advised to use the trtc
namespace.
using namespace trtc;
Note:
- For more information on how to configure the Android Studio C/C++ development environments, please see Add C and C++ code to your project.
- Currently, only the TRTC edition of the SDK supports C++ APIs. For more information on how to use C++ APIs, please see Overview.
Was this page helpful?