Example Source Code Running Guide
This article introduces how to quickly run the example source code and experience the basic audio and video call service.
Prepare Environment
Before running the example source code, please ensure that the development environment meets the following requirements: (the following descriptions take macOS development computer as an example):
-
Android Studio 2020.3.1 or above.
-
Android SDK 30, Android SDK Platform-Tools 30.x.x or above.
-
Android 4.4 or above, and an Android device or emulator that supports audio and video (it is recommended to use a real device). If it is a real device, please enable the "Allow USB Debugging" option.
-
The Android device and macOS development computer have been connected to the Internet.
-
When compiling the example source code for the first time, if there are no corresponding dependency libraries or build tools, Android Studio will automatically download the example source code, which may take a long time. Please wait patiently.
-
It is recommended to download specific Gradle and required dependency libraries. Please refer to Gradle Services to download. The Gradle-related versions used in the example source code are as follows:
- Gradle: 6.7.1 (view in the "project/gradle/wrapper/gradle-wrapper.properties" file).
- Android Gradle Plugin: 4.2.0 (view in the "project/build.gradle" file).
For version dependencies between Android Gradle Plugin, Gradle, and SDK Tool, please see: Android Gradle Plugin Version Description
Prerequisites
You have created a project in the ZEGOCLOUD Console and applied for a valid AppID and AppSign.
The SDK also supports Token authentication. If you need to upgrade the authentication method, please refer to How to upgrade from AppSign authentication to Token authentication.
Get Example Source Code
Download locally
Example Source Code Directory Structure
The following directory structure is the file structure of the android_java subdirectory. The file paths involved below are all relative to this directory.
.
├─ README.md
├─ README_zh.md
├─ VERSION.txt
└─ ZegoExpressExample
...
├─ AdvancedAudioProcessing # Advanced Audio Features
├─ AdvancedStreaming # Advanced Publishing and Playing Stream
├─ AdvancedVideoProcessing # Advanced Video
├─ CommonFeatures # Common Features
├─ CommonTools
├─ DebugAndConfig # Debugging and Configuration
├─ KeyCenter # Fill in the applied AppID and AppSign in the KeyCenter.java file inside
├─ Others # Other Features
├─ Quickstart # Quick Start
├─ Scenes # Best Practices
├─ build.gradle
├─ gradle
├─ gradle.properties
├─ gradlew
├─ gradlew.bat
├─ local.properties
├─ log
├─ main
│ ├─ .gitignore
│ ├─ build
│ ├─ build.gradle
│ ├─ libs # ZegoExpressVideo Android SDK storage directory
│ ├─ proguard-rules.pro
│ ├─ src
│ └─ wrap
└─ settings.gradleRun Example Source Code
- Find the Android Studio software icon on the development computer.

- Method 1: Log in to the Android Studio official website to download and install Android Studio and its related SDK Tools. Due to network restrictions of domestic operators and other reasons, developers need to ensure that their machine can connect to the website. If they cannot access it, it is recommended to choose method 2.
- Method 2: Use a search engine to search for "Android Studio download", "Android Studio installation", and "Android Studio SDK Tools installation", find available download source websites, and install related software and tools.
-
Open Android Studio and click "Open an Existing Project".

-
In the extracted example source code folder, select the ZegoExpressExample folder and click "Open" to open it.

-
Modify the "KeyCenter.java" file in the "./KeyCenter/src/main/java/im/zego/keycenter" directory, and fill in the "appID" and "appSign" required for SDK initialization.
WarningPlease use the AppID and AppSign obtained in the Prerequisites of this article to fill in correctly (you need to add L after the AppID), otherwise the example source code cannot run normally.

-
Connect the Android device to the development computer. When the device successfully enables "Developer Mode" and "USB Debugging" functions, you can see the "Running Devices" option box at the top of Android Studio change from the following figure:

to the following figure:

That is, Android Studio has successfully connected to the Android device, and the example source code can be run on the device.
Notes- When the development computer is connected to an Android device, most devices will pop up a prompt. The prompt information of different Android manufacturers is different. You can choose the USB mode according to the situation.
- After the Android device is connected to the development computer, you need to enable Developer Mode and USB Debugging functions on the device according to the situation (different Android manufacturers have different ways to enable them). For specific ways to enable them, developers may need to use a search engine by themselves. For example: if there is currently a device that has not enabled Developer Mode and USB Debugging functions, you can search for "Enable Developer Mode for a certain device" in the search engine to view the specific tutorial for enabling.
-
Click the "Run" button to compile and run the example source code.

Experience Audio and Video Call/Live Streaming Features
Run the project on a real device. After running successfully, you can see the local video picture.
For convenience, ZEGO provides a Web platform for debugging. On this page, enter the same AppID and RoomID, enter different UserIDs, and the corresponding Token, and you can join the same Room to communicate with the real device. When the audio and video call starts successfully, you can hear the remote audio and see the remote video picture.
FAQ
How to handle the error "Error: Illegal expression start :9" when running the downloaded example source code in Android Studio?
Since the AppID and AppSign in the downloaded example source code do not have specific values, please refer to step 4 in the "Run Example Source Code" section of this article to handle it.

