logo
On this page

Integrate the SDK


Prepare Environment

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

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

Integrate 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.

Import the SDK

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

Developers can implement SDK integration through any of the following methods.

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

If you cannot find the above field 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 in "allprojects".

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

    ...
    dependencies {
        ...
        implementation 'im.zego:express-audio: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:

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

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

    If you cannot find the above field 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 in "allprojects".

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

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

    And add an "ndk" node in 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 actual conditions. Usually when publishing the App, you only need to keep "armeabi-v7a" and "arm64-v8a", which can reduce the APK 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 the "other files (except .aar files)" from the "release/Library/" directory after extraction to your project directory, such as "app/libs".

Note
  • The "include" directory in 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 in Android Studio for a better development experience. For details, please refer to How to View API Comments and Documentation for Express Android SDK?
  1. Add SDK references. Open the "build.gradle" file in the "app" directory.

    1. Add an "ndk" node in 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 actual conditions. Usually when publishing the App, you only need to keep "armeabi-v7a" and "arm64-v8a", which can reduce the APK size.

  1. Add a "sourceSets" node in 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']
    }
}
  1. Import all jars under "libs" in the "dependencies" node.

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

Set 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.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" />
Warning
  • Because 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 Android versions below 6.0 need to declare it. Android 6.0 and above do not need to declare it.
String[] permissionNeeded = {
    "android.permission.RECORD_AUDIO"};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (ContextCompat.checkSelfPermission(this, "android.permission.RECORD_AUDIO") != PackageManager.PERMISSION_GRANTED) {
        //101 is requestCode, which can be any number greater than 0 and will be passed to the permission request result callback onRequestPermissionsResult
        requestPermissions(permissionNeeded, 101);
    }
}

The specific permission descriptions are as follows:

NecessityPermissionPermission DescriptionReason for Request
Required PermissionsINTERNETNetwork access permission.Basic SDK functions require network connection to be used.
ACCESS_WIFI_STATEGet current WiFi status permission.The SDK performs different operations based on network status changes. For example, when the network reconnects, the SDK internally restores all states before the network disconnection, and users do not need to perform additional operations.
ACCESS_NETWORK_STATEGet current network status permission.
RECORD_AUDIORecord audio permission.This permission is required when sending audio.
BLUETOOTHConnect to Bluetooth device permission.

This permission is required when connecting to Bluetooth devices.

Warning

Regarding BLUETOOTH permission: Only Android versions below 6.0 need to declare it. Android 6.0 and above do not need to declare it.

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. For example, if a current call status is detected, the SDK will automatically stop using audio devices until the call ends.
WRITE_EXTERNAL_STORAGEBuilt-in SDK write permission.If you need to use the media player or sound effects player to load media resource files from 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 the SDK's interruption event handling, so it only needs to be declared in the AndroidMainfest.xml file and does not need to be dynamically requested (unless there is a business requirement).

Prevent 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 of Integrated Native SDKs?

Previous

Run Example Source Code

Next

Implementing Voice Call