Android

更新时间:
复制 MD 格式

This topic describes how to integrate the software development kit (SDK) for Android.

Prerequisites

For more information about the environment requirements for Android, see Limits.

Integrate the SDK

Method 1: Integrate using Maven (Recommended)

  1. You can add the Maven repository address to the build.gradle file in the root directory.

    allprojects {
        repositories {
            google()
            jcenter()
            // Add the Maven address required for RTC.
            maven {
                url "http://maven.aliyun.com/nexus/content/groups/public/"
            }
        }
    }
  2. In the app/build.gradle file of the project, you can add the following lines.

    dependencies {   
            ...   
        // The RTC SDK dependency.
        implementation 'com.aliyun.rtc:AliRTC-Full:1.17.9.2005112'
    }
    Note

    The Maven dependency version is for reference only. To obtain the latest Maven dependency, see SDK downloads.

  3. In the app/src/main/AndroidManifest.xml file, you can add the following code to obtain the required device permissions.

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> 

    If your Android project's targetSdkVersion is 31 or later, you must dynamically request the android.permission.BLUETOOTH_CONNECT permission in your code to use Bluetooth features. For more information, see the official Android documentation.

  4. Optional: You can configure settings to prevent code obfuscation.

    In the proguard-rules.pro file, you can add -keep configurations for classes to prevent the obfuscation of public class names in the RTC SDK.

    -keep class com.serenegiant.**{*;}
    -keep class org.webrtc.**{*;}
    -keep class com.alivc.**{*;}    

Method 2: Integrate manually

  1. You can download and decompress the Android SDK. For the download link, see SDK downloads.

  2. You can copy the AliRTCSdk.aar SDK file to the libs folder in the App module.

  3. In the app/src/main/AndroidManifest.xml file, you can add the following code to obtain the required device permissions.

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> 

    If your Android project's targetSdkVersion is 31 or later, you must dynamically request the android.permission.BLUETOOTH_CONNECT permission in your code to use Bluetooth features. For more information, see the official Android documentation.

  4. Optional: You can configure settings to prevent code obfuscation.

    In the proguard-rules.pro file, you can add -keep configurations for classes to prevent the obfuscation of public class names in the RTC SDK.

    -keep class com.serenegiant.**{*;}
    -keep class org.webrtc.**{*;}
    -keep class com.alivc.**{*;}    

What to do next

After you integrate the SDK, you can implement the basic features of Real-Time Communication. For more information, see Implement basic features for Android.