tencent cloud

Feedback

Last updated: 2022-09-26 11:41:59
    This document describes how to import the SDK into your project.
    
    

    Environment Requirements

    Android Studio 3.5 or later.
    Android 4.1 (SDK API level 16) or later

    Step 1. Import the SDK

    Method 1. Automatic loading (aar)

    The TRTC SDK has been released to the mavenCentral repository, and you can configure Gradle to download updates automatically.
    1. Add the TRTC SDK dependency to dependencies.
    dependencies {
    implementation 'com.tencent.liteav:LiteAVSDK_TRTC:latest.release'
    }
    2. In defaultConfig, specify the CPU architecture to be used by your application.
    defaultConfig {
    ndk {
    abiFilters "armeabi-v7a", "arm64-v8a"
    }
    }
    explain
    Currently, the TRTC SDK supports armeabi-v7a, and arm64-v8a.
    3. Click
    
    Sync Now to automatically download the SDK and integrate them into your project.

    Method 2. Download the SDK and import it manually

    1. Download the SDK and decompress it locally.
    2. Copy the decompressed AAR file to the app/libs directory of your project.
    3. Add flatDir to build.gradle under your project's root directory to specify the local path for the repository.
    
    
    4. Add code in app/build.gradle to import the AAR file.
    
    
    5. In defaultConfig of app/build.gradle, specify the CPU architecture to be used by your application.
    defaultConfig {
    ndk {
    abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
    }
    }
    explain
    Currently, the TRTC SDK supports armeabi, armeabi-v7a, and arm64-v8a.
    6. Click
    
    Sync Now to integrate the TRTC SDK.

    Step 2. Configure app 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.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-feature android:name="android.hardware.camera.autofocus" />
    notice
    Do not set android:hardwareAccelerated="false". Disabling hardware acceleration will result in failure to render remote users' videos.

    Step 3. Set 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.** { *;}
    

    Using SDK Through C++ APIs (Optional)

    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, skip this step.
    1. First, you need to integrate the TRTC SDK by importing JAR and SO libraries as instructed above.
    2. 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})
    3. Use the namespace: The methods and types of cross-platform C++ APIs are all defined in the trtc namespace. To simplify your code, we recommend you use the trtc namespace.
    using namespace trtc;
    explain
    For more information on how to configure the Android Studio C/C++ development environments, 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, see Overview.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support