logo
Video Call
On this page

Integrating the SDK

2024-05-06

Prerequisites

Before integrating the ZEGO Express SDK, ensure your development environment meets the following requirements:

  • Android Studio 2020.3.1 or later.
  • Android SDK 25, Android SDK Build-Tools 25.0.2, Android SDK Platform-Tools 25.x.x or later.
  • Android 4.4 or later, with an Android device that supports audio and video.
  • The Android device is connected to the Internet.

Integrating the SDK

(Optional) Create a New Project

  1. Open Android Studio and select the "File > New > New Project" menu.

  2. Fill in the project name and project storage path.

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

Importing the SDK

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

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

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

    Warning

    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.

    For related information, please refer to Android Gradle Plugin Release Note v7.1.0.

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

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

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

    ...
    allprojects {
        repositories {
            maven { url 'https://maven.zego.im' }
            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 Release Notes for the latest SDK version and replace x.y.z with the specific version number.

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

Method 2: Manual Integration by Copying SDK AAR File

  1. Please refer to the Download documentation 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".

    Note

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

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

    ...
    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. For related information, please refer to Android Gradle Plugin Release Note v7.1.0. In this case, please follow the steps below:

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

    ...
    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 an "ndk" node to the "defaultConfig" node to specify the supported architectures.

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

    Decide which architectures to support based on your actual situation. Usually when releasing the App, you only need to keep "armeabi-v7a" and "arm64-v8a", which can reduce the APK package size.

Method 3: Manual Integration by Copying SDK JAR and SO Files

  1. Please refer to the Download documentation to download the latest version of the SDK and extract it.

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

    Note
    • The "include" directory under the architecture directory is the C++ header file of the SDK. If you only use Java interfaces for development, you can ignore it.
    • "ZegoExpressEngine-sources.jar" is the source code package. You can import it in Android Studio for a better development experience. For details, please refer to How to view API annotations and documentation for Express Android SDK?
  3. Add SDK references and open the "build.gradle" file in the "app" directory.

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

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

      Decide which architectures to support based on your actual situation. Usually when releasing the App, you only need to keep "armeabi-v7a" and "arm64-v8a", which can reduce the APK package size.

    2. Add a "sourceSets" node to the "android" node to specify the directory where "libs" is located.

      Note

      The "libs" directory in the example code is only for illustration. Developers can fill in according to the actual path.

      sourceSets {
          main {
              jniLibs.srcDirs = ['libs']
          }
      }
    3. Import all jar files under "libs" in the "dependencies" node.

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

Setting Permissions

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

Go to the "app/src/main" directory, open the "AndroidManifest.xml" file, and add 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" />

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

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

<feature android:name="android.hardware.camera" />
<feature android:name="android.hardware.camera.autofocus" />
Warning
  • Since Android 6.0 requires dynamic permission requests for some important permissions, you cannot only apply for static permissions through the "AndroidMainfest.xml" file. Therefore, you also need to refer to the following code, where "requestPermissions" is a method of "Activity".
  • Regarding BLUETOOTH permission: Only required for Android 6.0 and below, no need to declare 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 requestCode, can be any number greater than 0, will be passed to the permission request result callback onRequestPermissionsResult
        requestPermissions(permissionNeeded, 101);
    }
}

The specific permission descriptions are as follows:

NecessityPermissionPermission DescriptionReason for Application
Required PermissionsINTERNETNetwork access permission.Basic SDK functions need to be used when connected to the Internet.
ACCESS_WIFI_STATEGet current WiFi status permission.The SDK performs different operations based on changes in network status. For example, when the network reconnects, the SDK internally restores all states when the network was disconnected, and users do not need to perform additional operations.
ACCESS_NETWORK_STATEGet current network status permission.
CAMERACamera access permission.This permission is required when previewing and sending video.
RECORD_AUDIOAudio recording permission.This permission is required when sending audio.
BLUETOOTH

Bluetooth device connection permission.

This permission is required when connecting to Bluetooth devices.

Warning

Only required for Android 6.0 and below, no need to declare for Android 6.0 and above.

MODIFY_AUDIO_SETTINGSModify audio configuration permission.This permission is required when modifying audio device configuration.
Optional PermissionsREAD_PHONE_STATEAllow read-only access to phone status, including current call status.The SDK starts and stops audio devices based on the current call status. If a call status is detected, the SDK automatically stops using audio devices until the call ends.
WRITE_EXTERNAL_STORAGEBuilt-in SDK write permission.If you need to use the media player or audio effect player to load media resource files in Android external storage, you need to apply for this permission, otherwise the SDK cannot load resources.
Note

The optional permission "android.permission.READ_PHONE_STATE" is only used to implement SDK interrupt event handling, so it only needs to be declared in the AndroidMainfest.xml file and does not need to be dynamically applied for (unless there is a business requirement).

Preventing Code Obfuscation

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

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

How to reduce the App size integrated with Native SDK?

Previous

Example Source Code Running Guide

Next

Implement Video Call