Integrate the SDK
Set up the development environment
Before integrating the ZEGO Express SDK, make sure the development environment meets the following requirements:
- Android Studio 2020.3.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.4 or later and supports audio and video. We recommend you use a real device.
- The Android device is connected to the internet.
Create a new project
Skip to this step if a project already exists.
Create a new project
Open Android Studio, select File > New > Project.
Configure your new project with Application name and Project location.
All other items in the panel can be left as their defaults, click Next and then click Finish.
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
If your Android Gradle Plugin is v7.1.0 or later: go to the root directory of your project, open the
settings.gradle
file, and add the following line to thedependencyResolutionManagement
:... dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { maven { url 'https://storage.zego.im/maven' } google() mavenCentral() } }
If you can't find the above fields in
settings.gradle
, it's probably because your Android Gradle Plugin version is lower than v7.1.0.For more details, see Android Gradle Plugin Release Note v7.1.0.
If your Android Gradle Plugin is earlier than 7.1.0: go to the root directory of your project, open the
build.gradle
file, and add the following line to theallprojects
:... allprojects { repositories { maven { url 'https://storage.zego.im/maven' } google() mavenCentral() } }
Go to the
app
directory, open thebuild.gradle
file, and add the following line to thedependencies
. (x.y.z is the SDK version number, to obtain the latest version number, see ZEGO Express-Video Android SDK Release History)... dependencies { ... implementation 'im.zego:express-video:x.y.z' }
Method 2: Manually add the SDK to the project
Download the latest version of SDK. For details, see SDK downloads .
Extract the files from the SDK packages into your project directory, for example,
app/libs
.Add SDK Import Statements. Open the file
app/build.gradle
, and add the following contents:Add the
ndk
node inside thedefaultConfig
node to specify the supported ABIs.ndk { abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' }
Add the
sourceSets
node inside theandroid
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.
sourceSets { main { jniLibs.srcDirs = ['libs'] } }
Add the following code in the
dependencies
node.dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) ...... }
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" />
<!-- 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" />
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);
}
}
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.**{*;}