Before integrating the ZEGO Express SDK, please make sure that your development environment meets the following requirements:
To know Android Studio's version changes, refer to the Android Studio release notes.
Open Android Studio and select "File > New > New Project" from the menu.
Enter the project name and project storage path.
Leave the other settings as default, click "Next", and finally click "Finish" to complete the new project creation.
The supported platform architectures currently include: armeabi-v7a, arm64-v8a, x86, x86_64.
Developers can integrate the SDK using any of the following methods.
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()
}
}
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'
}
Please refer to the SDK downloads document to download the latest version of the SDK and extract it.
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.
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'
}
}
}
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.
Please refer to the SDK downloads document to download the latest version of the SDK and extract it.
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?
Add the SDK reference by opening the "build.gradle" file under the "app" directory.
Add the "ndk" node under the "defaultConfig" node to specify the supported architectures.
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
Add the "sourceSets" node under the "android" node, specifying the directory where "libs" is located.
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
Import all the jars under the "libs" directory in the "dependencies" node.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
......
}
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" />
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).
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.**{*;}