Last updated: 2021-05-12 17:10:08

    This document describes how to quickly integrate the Tencent Cloud TRTC SDK for Android into your project in the following steps.

    Development Environment Requirements

    • Android Studio 3.5 or above.
    • Android 4.1 (SDK API 16) or above.

    Integrating the SDK (aar)

    You can choose to use Gradle for automatic loading or manually download the aar and import it into your current project.

    Method 1. Automatic loading (aar)

    The TRTC SDK has been released to the JCenter 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 ([TRTCSimpleDemo] is used as an example in this document), and then modify the app/build.gradle file in three simple steps to complete SDK integration:

    1. Add the TRTC SDK dependencies to 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 to use com.android.tools.build:gradle v2.x:
      dependencies {
            compile 'com.tencent.liteav:LiteAVSDK_TRTC:latest.release'
      }
      
    1. In defaultConfig, specify the CPU architecture to be used by the application.
      defaultConfig {
          ndk {
              abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
          }
      }
      

      Note:

      Currently, the TRTC SDK supports armeabi, armeabi-v7a, and arm64-v8a.

    2. Click Sync Now to automatically download and integrate the SDK into the project.

    Method 2. Manual download (aar)

    If JCenter cannot be connected to, you can manually download the SDK and integrate it into your project:

    1. Download the SDK.
    2. Copy the downloaded aar file to the app/libs directory of the project.
    3. Add flatDir to build.gradle under the project’s root directory and specify the local repository path.
    4. Add the code that imports the aar library to app/build.gradle.
    5. In defaultConfig of app/build.gradle, specify the CPU architecture to be used by the application.
      defaultConfig {
          ndk {
              abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
          }
      }
      

      Currently, the TRTC SDK supports armeabi, armeabi-v7a, and arm64-v8a.

    6. Click Sync Now to complete the integration of TRTC SDK.

    Integrating the SDK (jar)

    If you do not want to integrate the aar library, you can choose to integrate the TRTC SDK by importing the jar and so libraries:

    1. Download the jar library. The file path is SDK/LiteAVSDK_TRTC_xxx.zip (xxx indicates the version number of TRTC SDK).
    2. After decompression, you can get the libs directory which contains the jar files and so folders.
    3. Copy the extracted jar files as well as armeabi, armeabi-v7a, and arm64-v8a folders to the app/libs directory.
    4. Add the code that imports the jar library to app/build.gradle.
    5. Add the code that imports the so library to app/build.gradle.
      sourceSets {
          main {
              jniLibs.srcDirs = ['libs']
          }
      }
      
    6. In defaultConfig of app/build.gradle, specify the CPU architecture to be used by the application.
      defaultConfig {
          ndk {
              abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
          }
      }
      

      ?Currently, the TRTC SDK supports armeabi, armeabi-v7a, and arm64-v8a.

    7. Click Sync Now to complete the integration of TRTC SDK.

    Configuring Application Permissions

    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" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    

    Note:

    Do not run the android:hardwareAccelerated="false" code to disable hardware acceleration; otherwise, the video streams of the peer cannot be rendered.

    Setting Obfuscation Rules

    In the proguard-rules.pro file, add the classes related to the TRTC SDK to the "do not obfuscate" list:

    -keep class com.tencent.** { *; }
    

    Setting Application Packaging Parameters

    Add the following code to app/build.gradle:

    packagingOptions {
        pickFirst '**/libc++_shared.so'
        doNotStrip "*/armeabi/libYTCommon.so"
        doNotStrip "*/armeabi-v7a/libYTCommon.so"
        doNotStrip "*/x86/libYTCommon.so"
        doNotStrip "*/arm64-v8a/libYTCommon.so"
    }