AI Effects Beta
  • Platform
  • Framework / Engine
  • iOS
  • Android
  • macOS
  • Windows
  • Linux
  • Web
  • WeChat Mini Program

Integration

Update Time:2021-05-20 19:23

1 Prepare the Environment

Before starting to integrate ZegoEffects SDK, please make sure that the development environment meets the following requirements:

  • Android Studio 2.1 or above.
  • Android SDK 25, Android SDK Build-Tools 25.0.2, Android SDK Platform-Tools 25.x.x or above.
  • Android 9.0 or above, and an Android device or emulator that supports audio and video (recommended to use a real device).

2 Integrate SDK

2.1 (Optional) Create a New Project

This step takes how to create a new project as an example. If it is integrated into an existing project, you can ignore this step.
  1. Open Android Studio and select the "File > New > New Project".

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

  3. Others follow the default settings, click "Next", and finally click "Finish" to complete the new project creation.

2.2 Import SDK

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

  1. Please contact ZEGO business staff to obtain the latest version of the SDK.

  2. Unzip the SDK to the project directory, such as "app/libs".

    /Pics/AI_Vision/QuickStarts/integration_Android_1.png

  3. Add SDK reference, go to the "app" directory, and open the "build.gradle" file.

    • Add the "ndk" node to the "defaultConfig" node to specify the supported platform type.

      /Pics/AI_Vision/QuickStarts/integration_Android_2.png

      ndk {
        abiFilters'armeabi-v7a','arm64-v8a','x86_64'
      }
    • Add the "sourceSets" node to the "android" node and specify the directory where "libs" is located.

      The "libs" directory in the sample code is just an example, developers can fill in according to the actual path.

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

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

3 Set Permissions

According to the actual application needs, set the permissions required by the application.

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

<!-- Required permissions for SDK -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- Part of the permissions that App needs to use -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

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

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

Because Android 6.0 requires dynamic permissions to be applied for some of the more important permissions, you cannot apply for static permissions only through the "AndroidMainfest.xml" file. Therefore, you need to refer to and execute the following code, where "requestPermissions" is the method of "Activity".

String[] permissionNeeded = {
    "android.permission.CAMERA"};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (ContextCompat.checkSelfPermission(this, "android.permission.CAMERA") != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(permissionNeeded, 101);
    }
}

4 Prevent Code Obfuscation

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

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