118 lines
5.8 KiB
Markdown
118 lines
5.8 KiB
Markdown
# docker持续部署
|
||
构建镜像来自:https://github.com/MobileDevOps/flutter-sdk-image/
|
||
|
||
## 使用方法
|
||
1. 复制文件,并编辑其中的代理设置
|
||
```bash
|
||
cp .docker/.env.example .docker/.env
|
||
# ~/.gradle 如不存在请新建,该目录缓存一些gradle包
|
||
mkdir -p ~/.gradle && chmod -R 777 ~/.gradle
|
||
cp .docker/gradle.properties.example ~/.gradle/gradle.properties
|
||
```
|
||
|
||
2. 构建命令
|
||
```bash
|
||
cd <path-to-this-repo>
|
||
|
||
# 构建目录,防止目录权限问题
|
||
mkdir /tmp/build-cache
|
||
echo 'hello!' > /tmp/build-cache/isMe.txt
|
||
chown -R 999:996 /tmp/build-cache
|
||
|
||
# 构建sky版本APK
|
||
docker run --rm -it \
|
||
--env-file .docker/.env \
|
||
-v .:/home/mobiledevops/app \
|
||
-v /tmp/build-cache/:/home/mobiledevops/app/build/ \
|
||
-v ~/.gradle/:/home/mobiledevops/.gradle/ \
|
||
-v ~/android-sdk-linux:/opt/android-sdk-linux \
|
||
mobiledevops/flutter-sdk-image:3.16.4 \
|
||
flutter build apk --release --flavor sky -t lib/main_sky_full.dart
|
||
|
||
```
|
||
|
||
3. 构建完成后,APK文件在build/app/outputs/flutter-apk目录下
|
||
|
||
|
||
## 排除故障
|
||
### 内存要求
|
||
4G内存下经常有异常崩溃,建议虚拟机8G内存
|
||
|
||
### 测试谷歌连接
|
||
```bash
|
||
# flutter以及maven 下载地址是否正常
|
||
curl -i https://storage.googleapis.com/flutter_infra_release/
|
||
```
|
||
|
||
### 卡在Running Gradle task 'assembleSkyRelease'...
|
||
这一步最耗时的是在下载maven仓库的依赖,如果卡在这里,可能是代理设置有问题,
|
||
请检查代理~/.gradle/gradle.properties中配置的代理,代理面板是否有请求输出
|
||
|
||
在网络请求平息了之后,又进入了漫长到令人绝望的等待中,这时候你可能会怀疑地球是否仍在转动,我们是否陷入了是时空停滞,别担心,这大概是由于计算机性能太低,或者在CPU受限的虚拟机中导致的,你可以在另外的窗口运行htop命令,或直接查看宿主机的CPU使用率,来观察系统是否处于卡顿(多线程编译导致的)以及进程树列表是否在变动,这些观察可以让你继续耐心等待,直到屏幕出现一片红色的报错信息。
|
||
|
||
如果在报错信息中看到正在编译XX或者下载XX,没有看到任何错误但是终止了,这可能是内存不够导致的崩溃。
|
||
|
||
参考的信息
|
||
```bash
|
||
# du -sh ~/android-sdk-linux/
|
||
7.1G /root/android-sdk-linux/
|
||
|
||
# du -sh ~/.gradle/
|
||
4.6G /root/.gradle/
|
||
|
||
# du -sh /tmp/build-cache
|
||
514M /tmp/build-cache
|
||
|
||
```
|
||
|
||
正常的输出
|
||
```bash
|
||
mobiledevops@946e5e22d9c5:~/app$ flutter build apk --release --flavor sky -t lib/main_sky_full.dart
|
||
Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source!
|
||
|
||
Warning: The plugin camera_android requires Android SDK version 34.
|
||
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||
Warning: The plugin flutter_local_notifications requires Android SDK version 34.
|
||
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||
Warning: The plugin fluwx requires Android SDK version 34.
|
||
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||
Warning: The plugin google_maps_flutter_android requires Android SDK version 34.
|
||
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||
Warning: The plugin image_picker_android requires Android SDK version 34.
|
||
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||
Warning: The plugin url_launcher_android requires Android SDK version 34.
|
||
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||
Warning: The plugin video_player_android requires Android SDK version 34.
|
||
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||
Warning: The plugin webview_flutter_android requires Android SDK version 34.
|
||
For more information about build configuration, see https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||
One or more plugins require a higher Android SDK version.
|
||
Fix this issue by adding the following to /home/mobiledevops/app/android/app/build.gradle:
|
||
android {
|
||
compileSdkVersion 34
|
||
...
|
||
}
|
||
|
||
Flutter assets will be downloaded from https://mirrors.tuna.tsinghua.edu.cn/flutter. Make sure you trust this source!
|
||
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 2388 bytes (99.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
|
||
WARNING: [Processor] Library '/home/mobiledevops/.gradle/caches/modules-2/files-2.1/androidx.media2/media2-session/1.2.1/f927563711e36371c19b2e86fb7ccf1c3f259ca4/media2-session-1.2.1.aar' contains references to both AndroidX and old support library. This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
|
||
Example of androidX reference: 'androidx/media2/session/MediaBrowser$Builder'
|
||
Example of support library reference: 'android/support/v4/media/session/MediaSessionCompat$Token'
|
||
Note: Some input files use or override a deprecated API.
|
||
Note: Recompile with -Xlint:deprecation for details.
|
||
Note: Some input files use unchecked or unsafe operations.
|
||
Note: Recompile with -Xlint:unchecked for details.
|
||
Note: Some input files use unchecked or unsafe operations.
|
||
Note: Recompile with -Xlint:unchecked for details.
|
||
Running Gradle task 'assembleSkyRelease'... 257.0s
|
||
✓ Built build/app/outputs/flutter-apk/app-sky-release.apk (45.3MB).
|
||
mobiledevops@946e5e22d9c5:~/app$
|
||
exit
|
||
```
|
||
|
||
### 手动编译
|
||
```bash
|
||
cd android
|
||
./gradlew assembleSkyRelease
|
||
```
|