Integrate the SDK
Prerequisites
The development and running environments must meet the following requirements:
- Operating system and architecture: Linux operating system with the x86_64 architecture
- C runtime library: glibc 2.18 or above
- Java development tools: 64-bit JDK 8 or above, including the java, javac, and jar commands
- Command-line tools: Bash, curl, unzip
- Underlying dependency libraries: libasound(ALSA), libv4l2(v4l utils)
- The SDK depends on libasound (ALSA) and libv4l2 (v4l utils).
- CentOS (RHEL/Fedora): install them by running the
yum install alsa-lib-devel libv4l-develcommand. - Ubuntu (Debian/Deepin): install them by running the
apt install libasound2-dev libv4l-devcommand. - For other platforms and systems, install them by yourself.
- If cross-compilation is required, see the documents How to cross-compile the Linux alsa-lib dependency library? and How to cross-compile the Linux v4l-utils dependency library?, and make sure the libasound and libv4l2 dependency libraries are installed on the target machine.
You can run the following commands to check whether the server's running environment meets the requirements:
uname -m # Should output x86_64
getconf GNU_LIBC_VERSION # Should be glibc 2.18 or above
java -version
javac -versionDownload the SDK
See Download SDK or use the following curl command to download and extract the SDK:
curl -fL "https://artifact-sdk.zego.im/downloads/ZegoRecorder-linux-java.zip" \
-H "Referer: https://www.zegocloud.com" \
-o ZegoRecorder-linux-java.zip
unzip ZegoRecorder-linux-java.zipThe extracted directory structure is as follows:
ZegoRecorder-linux-java/
├── VERSION.txt
├── Document/
│ └── index.html
└── Library/
├── ZegoRecorder.jar
└── x86_64/libZegoRecorder.so| File or Directory | Purpose | Needs to Be Copied to the Project |
|---|---|---|
Library/ZegoRecorder.jar | Java APIs and JNI bridge classes | Required for compilation and running; add it to the classpath |
Library/x86_64/libZegoRecorder.so | JNI native dynamic library | Required for running; also included during deployment |
Document/ | Offline API documentation, open index.html to view | Keep as needed; not involved in compilation or running |
VERSION.txt | SDK version information | Recommended to keep for version verification |
Create a Project and Import the SDK
Create the working directory recorder-java-integration:
mkdir -p recorder-java-integration
cd recorder-java-integrationCreate the project under recorder-java-integration and put the SDK files into sdk/:
mkdir -p recorder-java/src/com/example recorder-java/sdk/Library/x86_64
cp sdk-download/release/Library/ZegoRecorder.jar recorder-java/sdk/Library/
cp sdk-download/release/Library/x86_64/libZegoRecorder.so recorder-java/sdk/Library/x86_64/
cp sdk-download/release/VERSION.txt recorder-java/sdk/
cd recorder-javaThe project structure is as follows:
recorder-java/
├── src/com/example/
└── sdk/
├── VERSION.txt
└── Library/
├── ZegoRecorder.jar
└── x86_64/libZegoRecorder.soCreate src/com/example/Main.java:
package com.example;
import com.zego.zegoliveroom.ZegoLiveRoom;
public final class Main {
public static void main(String[] args) {
ZegoLiveRoom sdk = new ZegoLiveRoom();
System.out.println("Recorder SDK: " + sdk.getSDKVersion());
}
}Compile, package, and run in the recorder-java directory:
mkdir -p out/classes
javac -encoding UTF-8 -cp sdk/Library/ZegoRecorder.jar \
-d out/classes src/com/example/Main.java
jar cfe out/recorder-app.jar com.example.Main -C out/classes .
export LD_LIBRARY_PATH="$PWD/sdk/Library/x86_64${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
java -Djava.library.path="$PWD/sdk/Library/x86_64" \
-cp "out/recorder-app.jar:sdk/Library/ZegoRecorder.jar" com.example.MainThe console printing Recorder SDK: <version> indicates the SDK is successfully integrated.
The final project structure is as follows:
recorder-java/
├── out
│ ├── recorder-app.jar
│ └── classes/com/example/
│ └── Main.class
├── src/com/example/
│ └── Main.java
└── sdk/
├── VERSION.txt
└── Library/
├── ZegoRecorder.jar
└── x86_64/libZegoRecorder.soFAQ
Check the include path or the classpath for compilation and running, and make sure the SDK for the corresponding language is used.
Check the deployment path and the dynamic library search path.
Use ldd to check the app, the SDK, and other libraries, and use an environment that satisfies all dependency requirements.
For example, check the dynamic library dependencies in the project directory:
ldd sdk/Library/x86_64/libZegoRecorder.soIf not found appears in the output, a runtime library is missing; if version ... not found appears in the output, the runtime library version does not meet the requirement. Install or update the corresponding runtime library.
Check that both the JVM and the .so library are x86_64, and make sure the JAR and the .so library are a matched pair.
