Real-Time Audio and Video
  • iOS
  • Android : Java
  • macOS
  • Windows
  • Linux
  • Web
  • WeChat Mini Program
  • Flutter
  • Electron
  • Unity3D
  • Cocos2D
  • React Native
  • uni-app
  • Introduction
  • SDK downloads
  • Sample codes
  • Quick starts
  • Common features
  • Best practices
  • Advanced streaming
  • Advanced video processing
  • Advanced audio processing
  • Others
  • Debugging and configuring
  • Error codes
  • API changes
  • Server APIs
  • API Documents
  • FAQ

Integrate the SDK

Last updated:2021-08-19 17:13

1 Set up the development environment

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

  • Android Studio 2.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.1 or later and supports audio and video. We recommend you use a real device.
  • The Android device is connected to the internet.

2 Integrate the SDK

2.1 Optional: 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.
  1. Configure your new project with Application name and Project location.

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

2.2 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 with JitPack

  1. 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://www.jitpack.io' }
             google()
             jcenter()
         }
     }
  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 {
        ...
        // x.y.z is the specific version number of the SDK, for example: 2.7.0
        // Latest version number can be get in the SDK release history.
        implementation 'com.github.zegolibrary:express-video:x.y.z'
    }
  • Starting from the 2.7.0 version, ZEGO changes the SDK hosted server from JitPack to JCenter, so you need to change the configuration in build.gradle to com.github.zegolibrary:express-video:x.y.z.

  • JCenter will stop uploading the new version of the SDK after 2021-03-31, the service will be disabled 2021-05-01. For more details, see Service End for JCenter .

  • Starting from the 1.11.0 version, the dependent command has been changed from implementation 'im.zego:express-engine-video:x.y.z' to implementation 'im.zego:express-video:x.y.z' . The use of the version under 1.11.0 will not be affected, but the follow-up will not be updated from "express-engine-video". We recommend all developers that use the old version switch to 1.11.0 or later version for integration.

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.

  1. Add SDK Import Statements. Open the file app/build.gradle, and add the following contents:
  • Add the ndk node inside the defaultConfig node to specify the supported ABIs.

/Pics/Android/ZegoLiveRoom/android_integration.png

```gradle
ndk {
    abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' 
}
```
  • 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.

```gradle
sourceSets {
    main {
        jniLibs.srcDirs = ['libs']
    }
}
```
  • Add the following code in the dependencies node.
```gradle
implementation fileTree(dir: 'libs', include: ['*.jar'])
```  

3 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" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

    <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);
    }
}

4 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.**{*;}