- Voice Call
- Resources & Reference
- Sample code
Sample source code running guide
This article describes how to quickly run the sample source code and experience basic audio and video calling services.
1 Prepare the environment
Before you attempt to integrate the ZEGO Express SDK, make sure that the development environment meets the following requirements (the following instructions are all based on a macOS computer):
- Android Studio 2020.3.1 or later.
To know Android Studio's version changes, refer to the Android Studio release notes.
- Android SDK 30, Android SDK Platform-Tools 30.xx or above.
- Android devices or emulators with an Android version of 4.4 or above and support audio and video calling (real devices are recommended). If you use a real device, please enable the Allow Debugging option.
- The Android device or macOS computer is connected to the Internet.
- Android Studio automatically provides sample codes when you compile the sample source code for the first time, and there is no corresponding dependency library or build tool. This process may take a long time. Please wait patiently.
- It is recommended that you download specific Gradle and required dependent libraries. Please refer to Gradle Services for download. The relevant versions of Gradle used in the sample source code are as follows:
- Gradle: 6.7.1 (see the "project/gradle/wrapper/gradle-wrapper.properties" file).
- Android Gradle Plugin: 4.2.0 (see the "project/build.gradle" file).
For version dependencies among Android Gradle Plugin, Gradle, and SDK Tool, please refer to Android Gradle Plugin Release Notes.
Go to ZEGOCLOUD Admin Console to create a new project, and get the AppID and AppSign of your project.
The SDK now also supports using Token for authentication, if you want to change your authentication mode, refer to the Guide for upgrading the authentication mode from using the AppSign to Token.
3 Sample source code directory structure
The following directory structure is the file structure of the
android_java subdirectory, and the file paths mentioned below are all relative to this directory.
├─ AdvancedAudioProcessing # Advanced audio features
├─ AdvancedStreaming # Advanced stream publish and play
├─ AdvancedVideoProcessing # Advanced video features
├─ CommonFeatures # Common functions
├─ DebugAndConfig # Debug and configure
├─ KeyCenter # Fill in the AppID and AppSign of the application in the KeyCenter.Java file
├─ Others # Other functions
├─ Quickstart # Quick start
├─ Scenes # Best practices
│ ├─ .gitignore
│ ├─ build
│ ├─ build.gradle
│ ├─ libs # ZegoExpressVideo Android SDK storage directory
│ ├─ proguard-rules.pro
│ ├─ src
│ └─ wrap
4 Run the sample source code
- Find the Android Studio software icon on the development computer.
How to install Android Studio on the 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 of Chinese operators and other factors, make sure that the computer can be connected to the Internet. If not, refer to method 2.
- Method 2: Use a search engine to search for "Android Studio download", "Android Studio installation", and "Android Studio SDK Tools installation" to find the source website where you can download the software and tools and install them.
Open Android Studio and click Open an Existing Project.
In the decompressed example source code folder, select the
ZegoExpressExamplefolder and open it.
The AppID and AppSign required for SDK initialization are missing in the sample source code. You need to modify the
KeyCenter.javafile in the
./KeyCenter/src/main/java/im/zego/keycenterdirectory. Please refer to the Prerequisites. Make sure the AppID and AppSign are correctly filled in (Note: L needs to be added after the AppID). Otherwise, the sample source code cannot run properly.
- Connect the Android device to the development computer. When you successfully enable the Developer mode and USB Debugging functions for the device, the Running Devices option box appears on Android Studio, as shown below: Change to the following figure: This means that Android Studio has been successfully connected to the Android device, and the sample source code can be run on the device.
- When the development computer is connected to an Android device, a prompt appears on most devices. Note that the prompt information varies based on Android manufacturers, and you can select the USB mode.
- When the Android device is connected to the development computer, you need to enable the Developer mode and USB Debugging function on the device (the method for enabling the mode and function varies based on Android manufacturers). The developer needs to select a specific method. For example, if the developer mode and USB debugging function are not enabled for a certain device, you can use a search engine to search for "a device enables the developer mode" to view the specific enabling method and related tutorials.
- Click Run to compile and run the sample source code.
5 Experience audio and video calling/live broadcast function
We recommend you run your project on a real device. If your app runs successfully, you should hear the sound and see the video captured locally from your device.
To test out the real-time audio and video features, visit the ZEGO Express Web Demo, and enter the same
RoomID to join the same room. If it runs successfully, you should be able to view the video from both the local side and the remote side, and hear the sound from both sides as well.
In audio-only scenarios, no video will be captured and displayed.
- Android Studio reports the following error: "Error: Illegal expression start: 9" when running the downloaded sample source code. How can this be resolved?
Since no specific values for AppID and AppSign exist in the downloaded sample source code, please refer to the Prerequisites in this article.