Documentation
ExpressVideoSDK Video Call
Documentation
Demo APP
SDK Center
API Center
FAQ
Code Market
Console
Sign Up
Log In
中文站 English
  • Documentation
  • Video Call
  • Develop your app
  • Integrate the SDK

Integrate the SDK

Last updated:2024-09-10 16:32

1. Prepare the Environment

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

  • Android Studio 2020.3.1 or later.

To know Android Studio's version changes, refer to the Android Studio release notes.

  • Android SDK 25, Android SDK Build-Tools 25.0.2, Android SDK Platform-Tools 25.x.x or later versions.
  • Android 4.4 or later versions, and Android devices that support audio and video.
  • The Android device is connected to the Internet.

2. Integrate the SDK

2.1 (Optional) Create a new project

This step shows how to create a new project. If you are integrating into an existing project, you can skip this step.
  1. Open Android Studio and select "File > New > New Project" from the menu.

  2. Enter the project name and project storage path.

  3. Leave the other settings as default, click "Next", and finally click "Finish" to complete the new project creation.

2.2 Import the SDK

The supported platform architectures currently include: armeabi-v7a, arm64-v8a, x86, x86_64.

Developers can integrate the SDK using any of the following methods.

Method 1: Automatic Integration (Recommended)

  1. Go to the project root directory, open the "settings.gradle" file, and add the following code to "dependencyResolutionManagement" section.

    If you cannot find the following fields in "settings.gradle", it may be because your Android Gradle Plugin version is lower than v7.1.0.

    Please refer to the Android Gradle Plugin Release Note v7.1.0 for more information.

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

    If your Android Gradle Plugin version is lower than v7.1.0, please follow these steps:

    Go to the project root directory, open the "build.gradle" file, and add the following code to "allprojects" section.

    ...
    allprojects {
        repositories {
            maven { url 'https://storage.zego.im/maven' }
            google()
            mavenCentral()
        }
    }
  2. Go to the "app" directory, open the "build.gradle" file, and add implementation 'im.zego:express-video:x.y.z' to "dependencies". Please check the latest version of the SDK from the Release Notes and replace x.y.z with the specific version number.

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

Method 2: Manually Integrate by Copying the SDK AAR File

Manually integrate by copying the SDK AAR file
  1. Please refer to the SDK downloads document to download the latest version of the SDK and extract it.

  2. Copy the "release/Library/ZegoExpressEngine.aar" file from the extracted AAR file to your project directory, such as "app/libs".

    The files in the "release/Library/" directory of the SDK package include:

    • ".aar" file: used when using this integration method, other files can be ignored.

    • Other files: used when using Method 3: Manually Integrate by Copying the SDK JAR + SO Files.

  3. Go to the project root directory, open the "settings.gradle" file, and add the following code to "dependencyResolutionManagement" section.

    ...
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
            flatDir {
                dir 'app/libs'
            }
        }
    }

    If you cannot find the above fields in "settings.gradle", it may be because your Android Gradle Plugin version is lower than v7.1.0. Please refer to the Android Gradle Plugin Release Note v7.1.0 for more information. In this case, please follow these steps:

    Go to the project root directory, open the "build.gradle" file, and add the following code to "allprojects" section.

    ...
    allprojects {
        repositories {
            google()
            mavenCentral()
            flatDir {
                dir 'app/libs'
            }
        }
    }
  4. Go to the "app" directory, open the "build.gradle" file, and add implementation(name: 'ZegoExpressEngine', ext: 'aar') to "dependencies".

    ...
    dependencies {
        ...
        implementation(name: 'ZegoExpressEngine', ext: 'aar')
    }

    And add the "ndk" node under the "defaultConfig" node to specify the supported architectures.

    ndk {
        abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
    }

    Decide which architectures to support based on the actual situation. Usually, only "armeabi-v7a" and "arm64-v8a" need to be kept when releasing the app to reduce the APK size.

Method 3: Manually Integrate by Copying the SDK JAR + SO Files

Manually integrate by copying the SDK JAR + SO files
  1. Please refer to the SDK downloads document to download the latest version of the SDK and extract it.

  2. Copy all the files (except the .aar file) from the "release/Library/" directory to your project directory, such as "app/libs".

    • The "include" directory under the architecture directory is the C++ header file of the SDK. If you only use the Java interface for development, you can ignore it.

    • "ZegoExpressEngine-sources.jar" is the source code package. You can import it into Android Studio for better development experience. For details, please refer to How to View API Comments and Documentation for Express Android SDK?

  3. Add the SDK reference by opening the "build.gradle" file under the "app" directory.

    1. Add the "ndk" node under the "defaultConfig" node to specify the supported architectures.

      ndk {
          abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
      }
      Decide which architectures to support based on the actual situation. Usually, only "armeabi-v7a" and "arm64-v8a" need to be kept when releasing the app to reduce the APK size.
  4. Add the "sourceSets" node under the "android" node, specifying the directory where "libs" is located.

    The "libs" directory in the example code is just an example. Developers should fill in the actual path according to their own situation.
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
  5. Import all the jars under the "libs" directory in the "dependencies" node.

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

3 Set permissions

Set the required permissions for the application according to the actual needs.

Go to the "app/src/main" directory and open the "AndroidManifest.xml" file, then add the permissions.

<!-- 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" />
  • Due to Android 6.0's requirement for dynamically requesting permissions for some important permissions, static permissions cannot be requested solely through the "AndroidManifest.xml" file. Therefore, you also need to refer to the following code, where "requestPermissions" is a method of the "Activity" class.
  • Regarding the BLUETOOTH permission: it only needs to be declared for Android versions below 6.0, and does not need to be declared for Android 6.0 and above.
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) {
        //101 is the requestCode, which can be any number greater than 0, and will be passed to the onRequestPermissionsResult callback for permission request result.
        requestPermissions(permissionNeeded, 101);
    }
}

Specific permission details are as follows:

Necessity Permission Permission Description Reason for Application
Required Permissions
INTERNET
Access to the network.
The basic functions of the SDK require internet access.
ACCESS_WIFI_STATE
Access to the current WiFi state.
The SDK will perform different operations based on the network state. For example, when the network is reconnected, the SDK will automatically restore the state when the network was disconnected, without requiring any additional operations from the user.
ACCESS_NETWORK_STATE
Access to the current network state.
CAMERA
Access to the camera.
This permission is required for previewing and sending videos.
RECORD_AUDIO
Recording audio.
This permission is required for sending audio.
BLUETOOTH
Connecting to Bluetooth devices.
This permission is required for connecting to Bluetooth devices.

Only needs to be declared for Android versions below 6.0. No declaration is needed for Android 6.0 and above.

MODIFY_AUDIO_SETTINGS
Modifying audio settings.
This permission is required for modifying audio device settings.
Optional Permissions
READ_PHONE_STATE
Allows read-only access to phone state, including the current call state.
The SDK will start or stop audio devices based on the current call state. For example, if the current state is a call, the SDK will automatically stop using the audio device until the call ends.
WRITE_EXTERNAL_STORAGE
Write permission for the built-in SDK.
If you need to use the media player or sound effect player to load media resource files from external storage in Android, you need to apply for this permission. Otherwise, the SDK will not be able to load resources.

The optional permission "android.permission.READ_PHONE_STATE" is only used to implement the SDK's interruption event handling. Therefore, it only needs to be declared in the AndroidManifest.xml file and does not need to be dynamically requested (additional handling is required if there is a demand from the business side).

4 Prevent code obfuscation

In the "proguard-rules.pro" file, add the -keep class configuration for the SDK to prevent obfuscation of the SDK's public class names.

-keep class **.zego.**{*;}
Page Directory
  • Free trial
  • 提交工单
    咨询集成、功能及报价等问题
    电话咨询
    400 1006 604
    Get Consulting
    Scan Wechat QR code