Before integrating the ZEGO Express SDK, make sure the development environment meets the following requirements:
Configure the development environment as follows:
After configuring the Flutter environment in any of the above development environments, run the flutter doctor
command at the terminal to download the required dependencies as prompted.
To create a project in Flutter, see Flutter - Get Started.
pubspec.yaml
file, add the zego_express_engine
dependencies as follows: Depends on pub (recommended):
dependencies:
flutter:
sdk: flutter
zego_express_engine: ^2.0.0
Depends on git:
dependencies:
flutter:
sdk: flutter
zego_express_engine:
git:
url: git@github.com:zegoim/zego-express-flutter-sdk.git
ref: main
flutter pub get
command at the terminal.Go to the app/src/main
directory, open the AndroidManifest.xml
file to add permissions.
<!-- Permissions required by the SDK -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<!-- Permissions required by the Demo App -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
Because Android 6.0 requires dynamic permissions to be applied for some more important permissions, you cannot apply for static permissions only through the "AndroidMainfest.xml" file. Please find a third-party flutter plug-in on pub to implement by yourself, or refer to the Android native layer and execute the following code, where "requestPermissions" is the method of "Activity".
String[] permissionNeeded = {
"android.permission.CAMERA",
"android.permission.RECORD_AUDIO"};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this, "android.permission.CAMERA") != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(this, "android.permission.RECORD_AUDIO") != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissionNeeded, 101);
}
}
The permissions are described specifically as follows:
Required | Permission | Description | Necessity |
---|---|---|---|
Required |
INTERNET |
The permission to access internet. |
Implementing basic featurues will require this permission. |
ACCESS_WIFI_STATE |
The permission to get the current WiFi status. |
The SDK executes different operations based on the current network status. For example, the SDK tries to reconnect when the network disconnection detected. |
|
ACCESS_NETWORK_STATE |
The permission to get the current network status. |
||
CAMERA |
The permission to access camera. |
This is required when previewing and sending videos. |
|
RECORD_AUDIO |
The permission to record audio. |
This permission is required when sending audios. |
|
BLUETOOTH |
The permission to connect bluetooth. |
This is required when connecting the bluetooth. |
|
MODIFY_AUDIO_SETTINGS |
The permission to modify audio configuration. |
This is required when modifying the audio device confogurations. |
|
Optional |
READ_PHONE_STATE |
The permission (read-only) to get the current device status, including the current call status. |
The SDK will enable or disable the audio device based on the current calling status. For example, the SDK stops using the audio device (until the calling is over) when a call is ongoing. |
WRITE_EXTERNAL_STORAGE |
The write permission of built-in SDK. |
If you need to use a media player or sound player to load media resource files in Android external storage, you need to apply for this permission, otherwise the SDK cannot load the resources. |
The optional permission android.permission.READ_PHONE_STATE
is only used to implement the processing of SDK interrupt events, so it only needs to be declared in the AndroidMainfest.xml file, and does not need to be dynamically applied for (you will need to process it separately if you got more needs).
Privacy - Camera Usage Description
Privacy - Microphone Usage Description
After the permission is added, it is shown in the figure below:
In index.html, use the <script> tag to import ZegoExpressWebFlutterWrapper.js from the /assets/packages/zego_express_engine directory in the ZEGO Express SDK for Flutter package.
Sample codes as below:
<!-- <your-project>/web/index.html -->
<!DOCTYPE html>
<html>
...
<body>
...
<script type="application/javascript" src="assets/packages/zego_express_engine/assets/ZegoExpressWebFlutterWrapper.js"></script>
...
</body>
</html>
Question 1: iOS: error when using Platform View: [VERBOSE-2:platform_view_layer.cc(28)] Trying to embed a platform view but the PaintContext does not support embedding
Solution: Open the iOS project that requires Platform View and add the field io.flutter.embedded_views_preview
to Info > Custom iOS Target Properties
with a value of YES
.
This setting is no longer required for Flutter 1.22 or later.
Question 2: iOS: fatal error: lipo: -extract armv7 specified but fat file: [...] does not contain that architecture
Solution: Usually occurs when switching iOS devices, which can be resolved by deleting the flutter-project-path/build/
and flutter-project-path/ios/DerivedData/
directories. (If you cannot find the DerivedData
folder, look for /Users/your-user-name/Library/Developer/Xcode/DerivedData/
).
Question 3: iOS: CDN: trunk URL couldn't be downloaded
or CDN: trunk Repo update failed
.
Solution: Open Terminal, execute cd
to go to the ios folder under your project's root directory (the directory where the Podfile
file is located), and run the pod repo update
.
NoClassDefFoundError
occurs at release after the Flutter is upgraded to V1.10 or above resulting in a Flutter crash. This is because code obfuscation is enabled by default in Flutter 1.10 or later. To solve this, go to the app/proguard-rules.pro
file and add the -keep
configuration for SDK to avoid code obfuscation.
```java
-keep class **.zego.**{*;}
```
Question 5: Android: Android platform crashes when creating and destroying the TextureRenderer frequently, and the following error occurs:**
OpenGLRenderer E [SurfaceTexture-0-4944-46] updateTexImage: SurfaceTexture is abandoned!
flutter E [ERROR:flutter/shell/platform/android/platform_view_android_jni.cc(39)] java.lang.RuntimeException: Error during updateTexImage (see logcat for details)
Solution: The cause of this issue is that the Flutter Engine caused thread insecurity when calling the updateTexImage()
and release()
of the SurfaceTexture, and this has been fixed in version 1.24-candidate.2
. For details, see Prevent a race between SurfaceTexture.release and updateTexImage .