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
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" }Add the SDK dependency to the
dependenciesblock in the build.gradle file of the app module.// Push SDK basic edition implementation 'com.alivc.pusher:AlivcLivePusher:x.y.z'Notex.y.zindicates the version number of Push SDK of Android. Replace it with the actual version number, such as 7.4.0. For information about the latest version number, see SDK download.You cannot integrate Push SDK and Player SDK (AliyunPlayer) at the same time. If you want to integrate both the SDKs, use ApsaraVideo MediaBox SDK instead. For more information, see Download all-in-one SDKs and Quick integration.
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
Download and decompress the Push SDK for Android package.
Copy the AAR file to the libs folder of the app module.
In the build.gradle file of the project, add the
flatDirconfiguration in therepositoriessection of theallprojectsblock.flatDir { dirs 'libs' }Add the reference to the AAR file in the
dependenciesblock of the build.gradle file of the app module.dependencies { implementation fileTree(dir: 'libs', include: ['*.aar']) }
Step 2: Configure a license
For information about how to configure a license for the SDK, see Integrate a 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.** { *; }Usage notes
For detailed API information, see API reference for Push SDK for Android (basic edition).
For sample code on how to use the SDK features, see Use Push SDK for Android.