全部產品
Search
文件中心

ApsaraVideo Live:SDK整合

更新時間:Nov 02, 2024

通過閱讀本文,您可以瞭解Android端推流SDK的整合方法。

環境要求

類別

說明

開發工具

推薦使用Android Studio

Android版本

支援Android 5.0及以上版本。

步驟一:整合SDK

Maven整合(推薦)

  1. 修改專案的build.gradle檔案,添加Maven倉庫地址。

    maven { url "https://maven.aliyun.com/nexus/content/repositories/releases" }
  2. 修改App的build.gradle檔案,在dependencies節點中添加SDK依賴。

    本文中引入的SDK版本號碼僅供參考,擷取最新的版本請參見SDK下載與發布記錄

    //以下SDK請根據自己的業務需要,選擇一種接入即可
    
    //1.基礎版推流SDK(不支援連麥)
    implementation 'com.alivc.pusher:AlivcLivePusher:6.17.0'
    //2.互動版推流SDK(支援連麥)
    implementation 'com.alivc.pusher:AlivcLivePusher_Interactive:6.17.0'
  3. 修改App的build.gradle檔案,添加App對應的CPU架構。

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

手動整合

  1. 下載並解壓推流SDK

  2. 複製SDK檔案*.aar到App模組下的libs檔案夾。

  3. 修改專案的build.gradle檔案,在allprojectsrepositories節點中增加flatDir配置。

    flatDir {
     dirs 'libs'
    }
  4. 修改App的build.gradle檔案,在dependencies節點中增加aar的引用。

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

步驟二:配置License授權

推流SDK升級到4.4.2及以後版本,接入一體化License服務,您需要推流SDK License整合指南

步驟三:配置App許可權

修改App的src/main/AndroidManifest.xml檔案,配置App許可權。

<!--  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" />

步驟四:配置混淆規則

修改App的proguard-rules.pro檔案,添加混淆規則。

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

相關文檔