All Products
Search
Document Center

ApsaraVideo Live:SDK integration

Last Updated:Nov 04, 2024

This topic describes how to integrate Push SDK for Android.

Environment requirements

Item

Description

Development tool

Android Studio is recommended.

Android version

Android 5.0 or later is required.

Step 1: Integrate Push SDK for Android

(Recommended) Integrate the SDK by using Maven

  1. Specify the URL of the Maven repository in the build.gradle file of the project.

    maven { url "https://maven.aliyun.com/nexus/content/repositories/releases" }
  2. Add the SDK dependency to the dependencies block in the build.gradle file of the app module.

    The SDK version in this topic is only for reference. To obtain the latest version of the SDK, see SDK download and release notes.

    // Specify the SDK edition and version based on your business requirements.
    
    //1. Basic edition of Push SDK for Android. This edition does not support co-streaming.
    implementation 'com.alivc.pusher:AlivcLivePusher:6.17.0'
    //2. Interactive edition of Push SDK for Android. This edition supports co-streaming.
    implementation 'com.alivc.pusher:AlivcLivePusher_Interactive:6.17.0'
  3. Specify the CPU architecture of your application in the build.gradle file of the app module.

    defaultConfig {
     ndk {
     abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
     }
    }

Manually integrate the SDK

  1. Download and decompress the Push SDK for Android package.

  2. Copy the AAR file to the libs folder of the app module.

  3. In the build.gradle file of the project, add the flatDir configuration in the repositories section of the allprojects block.

    flatDir {
     dirs 'libs'
    }
  4. Add the reference to the AAR file in the dependencies block of the build.gradle file of the app module.

    dependencies {
     implementation fileTree(dir: 'libs', include: ['*.aar'])
    }

Step 2: Configure a license

Push SDK 4.4.2 and later versions support all-in-one licenses. For more information, see Integrate the Push SDK license.

Step 3: Configure app permissions

Configure the required permissions in the src/main/AndroidManifest.xml file of the app module.

<!--  Used for network features  -->
<uses-permission android:name="android.permission.INTERNET" />
<!--  To check the network connection state of the device, you'll need to add the ACCESS_NETWORK_STATE permission.  -->
<!--  This permission does not require user consent at runtime, but needs to be declared in the app's AndroidManifest.xml.  -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!--  If the app needs to record audio, you need to declare the RECORD_AUDIO permission and request this permission at runtime  -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<!--  The application needs to access the device's camera  -->
<uses-permission android:name="android.permission.CAMERA" />

<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission
  android:name="android.permission.BLUETOOTH"
  android:maxSdkVersion="30" />
<uses-permission
  android:name="android.permission.BLUETOOTH_ADMIN"
  android:maxSdkVersion="30" />
<!-- Needed only if your app communicates with already-paired Bluetooth devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<!-- Only used by Demo for accessing storage files  -->
<!--  Storage permissions  -->
<uses-permission
  android:name="android.permission.READ_EXTERNAL_STORAGE"
  android:maxSdkVersion="32" />
<!-- Access image files -->
<uses-permission
  android:name="android.permission.READ_MEDIA_IMAGES"
  android:minSdkVersion="33" />
<!-- Write audio files -->
<uses-permission
  android:name="android.permission.READ_MEDIA_AUDIO"
  android:minSdkVersion="33" />
<!-- Write video files -->
<uses-permission
  android:name="android.permission.READ_MEDIA_VIDEO"
  android:minSdkVersion="33" />

<!-- Only used by Demo for screen recording and streaming  -->
<!-- Used for creating background tasks, not required by SDK -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- Requesting permission to create system overlay windows -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<!-- Only used by Demo for muting  -->
<!-- If this permission is not declared, the feature of automatically muting the stream during a phone call will not work -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Step 4: Configure obfuscation rules

Add obfuscation rules to the proguard-rules.pro file of the app module.

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

References