AI Effects
  • iOS
  • Android : Java
  • Overview
  • Release notes
  • SDK downloads
  • Demo app
  • Sample codes
  • Getting started
    • Integrate the SDK
    • Import resources and models
    • Online authentication
    • Implement basic image processing
  • Guides
    • Face beautification
    • Face shape retouch
    • Beauty makeups
    • Background segmentation
    • Face detection
    • Stickers
    • Filters
  • Tutorials
  • Error codes
  • Documentation
  • AI Effects
  • Getting started
  • Integrate the SDK

Integrate the SDK

Last updated:2022-11-29 14:49

Prerequisites

Make sure your development environment meets the following requirements:

  • Android Studio 2.1 or later
  • Android SDK 25, Android SDK Build-Tools 25.0.2, Android SDK Platform-Tools 25.x.x, or later
  • An Android device or emulator running on Android 5.0 or later (we recommend you use a real device)

Create a new project

  1. Launch Android Studio, and in the Welcome to Android Studio window, click Create New Project.

    If you have a project already opened, select File > New > New Project.

  2. In the Configure your project window, fill in the project name and the location to save the project.

  3. Use the default settings for other fields, then click Next, and then click Finish to complete the project creation.

Import the SDK

Currently, the SDK supports these Application Binary Interfaces (ABIs): arm64-v8a, armeabi-v7a, and x86_64.

To import the SDK, do the following:

  1. Contact the ZEGO team to get the latest version of the SDK.

  2. Extract the SDK package to your project directory, for example, app/libs.

    /Pics/AI_Vision/QuickStarts/integration_Android_1.png

  3. Open the app/build.gradle file, and add references to the SDK.

    • In the defaultConfig block, add the ndk block to specify the supported ABIs.

      /Pics/AI_Vision/QuickStarts/integration_Android_2.png

      ndk {
          abiFilters'armeabi-v7a','arm64-v8a','x86_64'
      }
    • In the android block, add the sourceSets block to specify the directory where the SDK library files are located.

      The libs directory in the following sample code is just an example. Use the actual path according to your project setup.

      sourceSets {
          main {
              jniLibs.srcDirs = ['libs']
          }
      }
    • In the dependencies block, add the following line to import all JAR files under the libs directory.

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

Add app permissions

Add the following permissions in the app/src/main/AndroidManifest.xml file for your app to access the devices according to your app's requirements.

<!-- 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-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

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

Request runtime permissions: Android 6.0 requires certain important permissions to be obtained at runtime. So, besides declaring permissions in your app's AndroidMainfest.xml file, you also need to add the following code to request the permissions at runtime.

Note: requestPermissions is a method of the 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);
    }
}

Prevent code obfuscation

In the proguard-rules.pro file, add the following line to prevent the classes of the ZegoEffects SDK from being obfuscated.

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