Live Streaming
  • iOS
  • Android : Java
  • macOS
  • Windows
  • Linux
  • Web
  • Flutter
  • Electron
  • Unity3D
  • React Native
  • Introduction
  • Sample codes
  • Client SDKs
    • SDK downloads
    • Release notes
  • Getting started
    • Integrate the SDK
    • Implement a basic live streaming
    • Use Tokens for authentication
    • Scenario-based audio/video config
  • Guides
    • Common video configuration
    • Common audio config
    • Real-time messaging
    • Enhancing live quailty
    • Stream mixing
    • Playing media files
    • Playing streams via URL
    • Basic face beautification features
    • Voice changing/Reverb/Stereo
    • Screen sharing
    • Local media recording
    • Advanced features
    • Quotas and Limits
  • Tutorials
  • Error codes
  • Client APIs
  • Server APIs

Integrate the SDK

Last updated:2023-03-07 14:32

Set up the development environment

Before integrating the ZEGO Express SDK, make sure the development environment meets the following requirements:

  • Android Studio 2020.3.1 or later
  • Android SDK Packages: Android SDK 25, Android SDK Build-Tools 25.0.2, Android SDK Platform-Tools 25.x.x or later.
  • An Android device or Simulator that is running on Android 4.4 or later and supports audio and video. We recommend you use a real device.
  • The Android device is connected to the internet.

Create a new project

Skip to this step if a project already exists.

Create a new project
  1. Open Android Studio, select File > New > Project.

  2. Configure your new project with Application name and Project location.

  3. All other items in the panel can be left as their defaults, click Next and then click Finish.

Import the SDK

The Android ABIs currently supported by the SDK: armeabi-v7a, arm64-v8a, x86, x86_64.

Choose either of the following methods to integrate the ZEGO Express SDK into your project.

Method 1: Integrate the SDK automatically

  1. If your Android Gradle Plugin is v7.1.0 or later: go to the root directory of your project, open the settings.gradle file, and add the following line to the dependencyResolutionManagement:

    ...
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            maven { url 'https://storage.zego.im/maven' }
            google()
            mavenCentral()
        }
    }

    If you can't find the above fields in settings.gradle, it's probably because your Android Gradle Plugin version is lower than v7.1.0.

    For more details, see Android Gradle Plugin Release Note v7.1.0.

    If your Android Gradle Plugin is earlier than 7.1.0: go to the root directory of your project, open the build.gradle file, and add the following line to the allprojects:

    ...
    allprojects {
        repositories {
            maven { url 'https://storage.zego.im/maven' }
            google()
            mavenCentral()
        }
    }
  2. Go to the app directory, open the build.gradle file, and add the following line to the dependencies. (x.y.z is the SDK version number, to obtain the latest version number, see ZEGO Express-Video Android SDK Release History)

    ...
    dependencies {
        ...
        implementation 'im.zego:express-video:x.y.z'
    }

Method 2: Manually add the SDK to the project

  1. Download the latest version of SDK. For details, see SDK downloads .

  2. Extract the files from the SDK packages into your project directory, for example, app/libs.

  3. Add SDK Import Statements. Open the file app/build.gradle, and add the following contents:

    1. Add the ndk node inside the defaultConfig node to specify the supported ABIs.

      ndk {
          abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
      }
    2. Add the sourceSets node inside the android node to specify the directory containing the SDK files.

      The directory libs is only an example for illustration, you can fill in based on the actual situation.

      sourceSets {
          main {
              jniLibs.srcDirs = ['libs']
          }
      }
    3. Add the following code in the dependencies node.

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

Add permissions

Permissions can be set as needed.

Open the file app/src/main/AndroidManifest.xml, and add the following code:

<!-- Permissions required by the SDK -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<!-- Permissions required by the App -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

Note: For Android 6.0 or later, some important permissions must be requested at runtime rather than declared statically in the file AndroidMainfest.xml, therefore, you need to add the following code to do so (requestPermissions is a method of an Android Activity).

String[] permissionNeeded = {
    "android.permission.CAMERA",
    "android.permission.RECORD_AUDIO"};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (ContextCompat.checkSelfPermission(this, "android.permission.CAMERA") != PackageManager.PERMISSION_GRANTED ||
        ContextCompat.checkSelfPermission(this, "android.permission.RECORD_AUDIO") != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(permissionNeeded, 101);
    }
}

Prevent class name obfuscation

To prevent the ZEGO SDK public class names from being obfuscated, you can add the following code in the file proguard-rules.pro.

-keep class **.zego.**{*;}