通过阅读本文,您可以了解Android端推流SDK的集成方法。

环境要求

类别

说明

开发工具

推荐使用Android Studio

Android版本

支持Android 5.0及以上版本。

步骤一:集成SDK

重要

如果同时集成直播推流SDK和播放器SDK,可能存在冲突问题,建议选择一体化SDK。您可以根据使用场景说明按场景集成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.** { *; }

相关文档