Android

更新时间:
复制 MD 格式

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

Prerequisites

For information about the specific prerequisites for Android, see Limits.

Integrate the SDK

Method 1: Integrate using Maven (Recommended)

  1. Add the Maven repository URL to the build.gradle file in the root directory:

    allprojects {
        repositories {
            google()
            jcenter()
            // Add the Maven URL for RTC.
            maven {
                url "http://maven.aliyun.com/nexus/content/groups/public/"
            }
        }
    }
  2. Add the following lines to the app/build.gradle file of your project:

    dependencies {   
            ...   
        // The RTC SDK dependency  
        implementation 'com.ding.rtc:dingrtc-full:3.0.0'
    }
    Note

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

  3. Add the following code to the app/src/main/AndroidManifest.xml file to obtain the required device permissions.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.ding.rtc">
    
        <!-- Network 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.CHANGE_WIFI_STATE" />
    
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <!-- Video permissions -->
        <uses-permission android:name="android.permission.CAMERA" />
        <!-- Audio recording permissions -->
        <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.WRITE_EXTERNAL_STORAGE" />
    
        <!-- The startBluetoothSco method for Bluetooth uses this permission -->
        <uses-permission android:name="android.permission.BROADCAST_STICKY"/>
    
        <application>
            <activity
                android:name="org.webrtc.mozi.JavaScreenCapturer$ScreenCaptureAssistantActivity"
                android:theme="@android:style/Theme.Translucent" />
        </application>
    
    </manifest>

    If your Android project has a targetSdkVersion of 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. Configure code obfuscation.

    In the proguard-rules.pro file, add the -keep class configuration to prevent the public class names of the Real-Time Communication (RTC) SDK from being obfuscated.

    -keep class org.webrtc.**{*;}
    -keep class com.ding.rtc.**{*;}    

Method 2: Manual integration

  1. Download and decompress the Android SDK. For the download link, see SDK download.

  2. Copy the DingRtc.aar SDK file to the libs folder in the App module.

  3. Add the following code to the app/src/main/AndroidManifest.xml file to obtain the required device permissions.

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.ding.rtc">
    
        <!-- Network 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.CHANGE_WIFI_STATE" />
    
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <!-- Video permissions -->
        <uses-permission android:name="android.permission.CAMERA" />
        <!-- Audio recording permissions -->
        <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.WRITE_EXTERNAL_STORAGE" />
    
        <!-- The startBluetoothSco method for Bluetooth uses this permission -->
        <uses-permission android:name="android.permission.BROADCAST_STICKY"/>
    
        <application>
            <activity
                android:name="org.webrtc.mozi.JavaScreenCapturer$ScreenCaptureAssistantActivity"
                android:theme="@android:style/Theme.Translucent" />
        </application>
    
    </manifest>

    If your Android project has a targetSdkVersion of 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. Configure code obfuscation.

    In the proguard-rules.pro file, add the -keep class configuration to prevent the public class names of the Real-Time Communication (RTC) SDK from being obfuscated.

    -keep class org.webrtc.**{*;}
    -keep class com.ding.rtc.**{*;}    

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.