Virtual Avatar
  • iOS
  • Android : Java
  • Overview
  • Client SDKs
  • Demo app
  • Getting started
    • Integrate the SDK
    • Create a virtual avatar
    • ZegoCharacterHelper instructions
  • Guides
  • Best practice
  • Error codes
  • Server APIs
  • Documentation
  • Virtual Avatar
  • Client SDKs
  • Run the sample code

Run the sample code

Last updated:2022-12-23 13:03

This document describes how to quickly run the sample source code and experience the Avatar service.

Prepare the environment

Before running the sample source code, ensure that the development environment satisfies the following requirements (take a development computer with macOS for example):

  • Android Studio is in version 4.0 or later.
  • Android SDK 30 and Android SDK Platform-Tools 30.x.x or later are used.
  • The Android system is in version 5.1 or later and supports audio and video Android devices or simulators (physical devices are recommended). If physical devices (real devices) are used, enable USB debugging.
  • Android devices have been connected to the Internet.
  • When you compile the sample source code for the first time, if there is no corresponding dependency library or build tool, Android Studio will automatically download the sample source code. This might take a long time.
  • We recommend that you download Gradle of a specific version and required dependency libraries. To download Gradle and libraries, please visit Gradle Services . The version of Gradle used in the sample source code is as follows:
    • Gradle: 7.0.2 (For details, see the project/gradle/wrapper/gradle-wrapper.properties file.)
    • Android Gradle plug-in: 4.1.0 (For details, see the project/build.gradle file.)

Prerequisites

  • You have created a project in the ZEGO Admin Console and obtained valid AppID and AppSign for the project.
  • You have contacted ZEGOCLOUD business personnel to obtain the package name of your project and grant related permissions.
  • You have obtained the SDK and the sample source code package from the Download page.

Directory structure of the sample source code

The following part is the subdirectory structure of the Avatar source code file. The file paths mentioned below are relative to this directory.

.
├── app
│   ├── build.gradle
│   ├── libs                                          # Avatar SDK directory
│   ├── proguard-rules.pro
│   └── src
│       ├── androidTest
│       ├── main
│       │   ├── AndroidManifest.xml
│       │   ├── assets                                 # Model resources
│       │   ├── java
│       │   │   └── im
│       │   │       └── zego
│       │   │           └── zegoavatarexample
│       │   │               ├── MainActivity.java      # Entry page (home page)
│       │   │               ├── activity               # API example page
│       │   │               ├── adapter                # Tools on the home page
│       │   │               ├── entity                 # Tools on the home page
│       │   │               ├── express                # Sample code collected by Express
│       │   │               ├── helper                 # ZegoCharacterHelper directory
│       │   │               ├── licensehelper          # Code related to online authentication
│       │   │               └── view                   # Tool view
│       │   └── res
│       └── test
├── build.gradle
├── gradle
├── gradle.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── settings.gradle

Run the source sample code

  1. Open Android Studio.

    /Pics/ZegoEffects/Android/android_studio_logo.png

    Methods for installing Android Studio on a development computer
    • Method 1: Log in to Android Studio official website to download and install Android Studio and its related SDK Tools.Due to network restrictions and other reasons in China, you need to ensure that the device can connect to the website. If the device cannot connect to the website, Method 2 is recommended.
    • Method 2: Use a search engine to search for "Download Android Studio", "Install Android Studio", and "Install Android Studio SDK Tools". Find a reliable source website from which you can download Android Studio and install Android Studio and related tools.
  1. Open Android Studio, click Open or Open an existing Android Studio project.

    /Pics/ZegoAvatar/Android/android_stuidio_open_project.png

  2. In the decompressed sample source code folder, select the "example" folder and click Open.

    /Pics/ZegoAvatar/Android/android_studio_select_example.png

  3. The authentication information (AppID and AppSign) required for SDK initialization is missing in the sample source code. You need to modify the ZegoAvatarConfig.java file in the example/app/src/main/java/im/zego/zegoavatarexample/licensehelper directory. Enter the obtained information stated in Prerequisites correctly. Otherwise, the sample source code cannot be run.

    /Pics/ZegoAvatar/Android/modify_appid_and_sign.png

  4. Find the app/build.gradle file and set applicationId to the package name provided when you apply for permissions.

    /Pics/ZegoAvatar/Android/modify_applicationid.png

  5. Model resources are large and are not packaged in the "example" path. In this case, you need to find the "assets" folder in the decompressed folder, and add all content under the folder to the example/app/src/main/assets path. SDK and ZegoCharacterHelper have been updated synchronously when the sample source code is packaged and do not need to be copied manually.

    /Pics/ZegoAvatar/Android/copy_assets.png

    The result is as follows:

    /Pics/ZegoAvatar/Android/add_assets.png

  6. Connect the Android device to the development computer. When Developer options and USB debugging are enabled, Android Studio changes from

    /Pics/ZegoAvatar/Android/has_device.png

    to:

    /Pics/ZegoAvatar/Android/has_device.png

    Android Studio has been successfully connected to the Android device to run the sample source code.

    • When the development computer is connected to Android devices, most devices will pop up a prompt. The prompt messages vary with Android device manufacturers, and the USB mode can be selected according to the situation.
    • When the Android device is connected to the development computer, it is necessary to enable the Developer options and USB debugging features on the device according to the situation. (The methods of enabling these features vary with Android device manufacturers.) You can search for specific methods using a search engine. For example, there is a device on which the Developer options and USB debugging features are not enabled. You can use a search engine to search for "Enable Developer options on a device" and find the tutorial on enabling this feature.
  7. Click Build and run to compile and run the sample source code.

    /Pics/ZegoAvatar/Android/run_demo.png

Page Directory