Skip to content

Commit 57e7b05

Browse files
committed
update flutter demo build docs.
1 parent 2111bfb commit 57e7b05

File tree

5 files changed

+184
-0
lines changed

5 files changed

+184
-0
lines changed
307 KB
Loading
390 KB
Loading
313 KB
Loading
410 KB
Loading
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
---
2+
title: Flutter Demo 的快速编译与运行
3+
hide_title: false
4+
sidebar_position: 2
5+
---
6+
7+
## 前言
8+
9+
本文将指导你从零开始,快速搭建并运行基于 OpenIMSDK 的 Flutter 即时通讯应用。本项目基于开源的 OpenIMSDK,集成 [`flutter_openim_sdk`](https://pub.dev/packages/flutter_openim_sdk),支持 iOS 和 Android 平台的即时通讯功能。相比 Twilio 或 Sendbird 等第三方云通信服务,OpenIMSDK 提供自托管部署,显著降低成本,同时确保数据安全与隐私。
10+
11+
## 1. 项目背景
12+
13+
OpenIMSDK 是一款开源即时通讯 SDK,提供高度可控的服务器部署和数据管理,适合对安全性和自主性要求高的场景。开发者可基于 OpenIMSDK 构建类似微信、Slack 或 Zoom 的应用,支持文本聊天、音视频通话等功能。
14+
15+
import demo_preview1 from './assets/preveiw1.zh-CN.jpeg';
16+
import demo_preview2 from './assets/preveiw2.zh-CN.jpeg';
17+
18+
<div style={{ display: 'flex', justifyContent: 'center', gap: '8px' }}>
19+
<img src={demo_preview1} alt="预览图" width="32%" />
20+
<img src={demo_preview2} alt="预览图" width="32%" />
21+
</div>
22+
23+
## 2. 环境准备
24+
25+
### 系统要求
26+
- **Windows**: 10 或更高版本
27+
- **macOS**: 14.6 或更高版本
28+
29+
### 开发工具
30+
- **Flutter**: 3.24.5(参考[官方安装指南](https://docs.flutter.cn/get-started/install)
31+
- **Xcode**: 15.4(用于 iOS 开发)
32+
- **Android Studio**: Koala | 2024.1.1 Patch 1
33+
- **Git**: 用于代码版本管理
34+
35+
### 服务端准备
36+
- 部署最新版本的 **OpenIM Server**(参考[官方 Docker Compose 部署指南](https://docs.openim.io/zh-Hans/guides/gettingStarted/dockerCompose))。
37+
- 确保本地网络可与服务端正常通信。
38+
39+
## 3. 获取示例项目
40+
41+
克隆示例项目代码:
42+
43+
```bash
44+
git clone https://github.com/openimsdk/openim-flutter-demo.git
45+
cd openim-flutter-demo
46+
```
47+
48+
## 4. 安装依赖
49+
50+
在项目根目录运行以下命令:
51+
52+
```bash
53+
flutter clean
54+
flutter pub get
55+
```
56+
57+
> **提示**:若依赖安装失败,检查 `pubspec.yaml` 中的版本兼容性,或运行 `flutter pub cache repair` 清理缓存。
58+
59+
## 5. 配置服务端地址
60+
61+
修改服务端地址以连接你的 OpenIM Server:
62+
63+
1. 打开 `openim_common/lib/src/config.dart` 文件。
64+
2. 更新 `_host` 常量为你的服务器 IP 或域名:
65+
```dart
66+
static const _host = "your-server-ip-or-domain";
67+
```
68+
69+
> **注意**
70+
> - 默认端口无需修改,除非服务端配置变更。
71+
> - 若使用 HTTPS 域名,需配置 Nginx 并确保证书有效。
72+
73+
## 6. 运行项目
74+
75+
通过以下命令运行项目:
76+
77+
```bash
78+
flutter run
79+
```
80+
81+
或者在 IDE(如 Android Studio 或 VS Code)中选择目标设备(iOS 或 Android)并点击“Run”。
82+
83+
## 7. 启用音视频通话
84+
85+
OpenIMSDK 开源版支持一对一音视频通话。启用该功能需:
86+
87+
1. 在服务端部署音视频服务(参考[LiveKit 服务器配置指南](https://github.com/openimsdk/chat/blob/main/HOW_TO_SETUP_LIVEKIT_SERVER.md))。
88+
2. 验证服务端配置,确保客户端可正常连接。
89+
90+
> **多人通话**:如需多人音视频或视频会议功能,请联系官方邮箱 `[email protected]` 获取支持。
91+
92+
## 8. 构建生产环境
93+
94+
### iOS
95+
生成 iOS 应用(`.ipa` 文件):
96+
97+
```bash
98+
flutter build ipa
99+
```
100+
101+
### Android
102+
生成 Android 应用(`.apk` 文件):
103+
104+
```bash
105+
flutter build apk
106+
```
107+
108+
构建产物位于 `build/` 目录。
109+
110+
## 9. 常见问题解答
111+
112+
### 1. 支持多语言吗?
113+
是的,Demo 默认支持中文和英文,可通过添加语言文件扩展其他语言。
114+
115+
### 2. 支持哪些平台?
116+
目前支持 iOS(最低版本 13.0)和 Android。
117+
118+
### 3. Android Release 包白屏?
119+
Release 包可能因代码混淆导致白屏,尝试禁用混淆:
120+
121+
```bash
122+
flutter build apk --no-shrink
123+
```
124+
125+
或在 `android/app/build.gradle``release` 配置中添加:
126+
127+
```gradle
128+
release {
129+
minifyEnabled false
130+
useProguard false
131+
shrinkResources false
132+
}
133+
```
134+
135+
### 4. 需要代码混淆怎么办?
136+
在混淆规则中添加以下配置,保留 OpenIMSDK 相关类:
137+
138+
```bash
139+
-keep class io.openim.** { *; }
140+
-keep class open_im_sdk.** { *; }
141+
-keep class open_im_sdk_callback.** { *; }
142+
```
143+
144+
### 5. Android 包无法在模拟器运行?
145+
Demo 默认移除部分 CPU 架构,需添加模拟器支持:
146+
147+
`android/app/build.gradle` 中配置:
148+
149+
```gradle
150+
ndk {
151+
abiFilters "armeabi-v7a", "x86"
152+
}
153+
```
154+
155+
### 6. iOS 构建或运行报错?
156+
确保 CPU 架构为 `arm64`,并按以下步骤操作:
157+
158+
```bash
159+
flutter clean
160+
flutter pub get
161+
cd ios
162+
rm -f Podfile.lock
163+
rm -rf Pods
164+
pod install
165+
```
166+
167+
连接真机后运行或归档(Archive)。
168+
169+
![iOS CPU 设置](https://user-images.githubusercontent.com/7018230/155913400-6231329a-aee9-4082-8d24-a25baad55261.png)
170+
171+
### 7. ffmpeg不能使用?
172+
可以自行编译或者使用其它源,例如: https://github.com/carl-designlibro/ffmpeg-kit
173+
174+
## 10. 结语
175+
176+
通过本文,你应已成功运行 OpenIMSDK 的 Flutter 示例项目。OpenIMSDK 提供高安全性和低成本的通信解决方案,适合企业级即时通讯需求。
177+
178+
如遇问题,欢迎:
179+
-[GitHub Issues](https://github.com/openimsdk/openim-flutter-demo/issues) 提交反馈。
180+
- 访问 [OpenIMSDK 官网](https://www.openim.io)[官方文档](https://docs.openim.io)
181+
- 联系官方邮箱 `[email protected]`
182+
183+
更多资源:
184+
- [GitHub 仓库](https://github.com/openimsdk)

0 commit comments

Comments
 (0)