Update dart.yml #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Flutter Windows, Linux, and Android Release | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
# build-windows: | |
# runs-on: windows-latest | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v4 | |
# - name: Set up Flutter | |
# uses: subosito/flutter-action@v2 | |
# with: | |
# flutter-version: '3.x' # 根据需要指定 Flutter 版本 | |
# - name: Enable Windows Desktop Support | |
# run: flutter config --enable-windows-desktop | |
# - name: Add Windows Platform Support | |
# run: flutter create --platforms=windows . | |
# - name: Install dependencies | |
# run: flutter pub get | |
# - name: Build Windows Release | |
# run: flutter build windows --release | |
# - name: Upload Windows Release Artifact | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: windows-release | |
# path: build/windows/x64/runner/Release/ | |
# build-linux: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v4 | |
# - name: Set up Flutter | |
# uses: subosito/flutter-action@v2 | |
# with: | |
# flutter-version: '3.x' # 根据需要指定 Flutter 版本 | |
# - name: Install dependencies for Linux build | |
# run: | | |
# sudo apt-get update | |
# sudo apt-get install -y cmake ninja-build pkg-config libgtk-3-dev liblzma-dev | |
# - name: Enable Linux Desktop Support | |
# run: flutter config --enable-linux-desktop | |
# - name: Add Linux Platform Support | |
# run: flutter create --platforms=linux . | |
# - name: Install Flutter dependencies | |
# run: flutter pub get | |
# - name: Build Linux Release | |
# run: flutter build linux --release | |
# - name: Upload Linux Release Artifact | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: linux-release | |
# path: build/linux/x64/release/bundle/ | |
build-android: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: '3.x' # 根据需要指定 Flutter 版本 | |
# 为避免旧 Android 工程问题,创建一个全新的 Flutter Android 项目 | |
- name: Install Flutter dependencies (original project) | |
run: flutter pub get | |
- name: Create new Flutter Android project | |
run: flutter create -t app new_android_project | |
- name: Migrate code to new project | |
run: | | |
# 移除新项目自动生成的 lib 目录 | |
rm -rf new_android_project/lib | |
# 将现有项目中的 lib 目录迁移过去 | |
cp -R lib new_android_project/ | |
# 用现有项目的 pubspec.yaml 替换新项目中的文件 | |
cp pubspec.yaml new_android_project/ | |
# 如果存在 assets 目录,也一起迁移 | |
if [ -d assets ]; then cp -R assets new_android_project/; fi | |
- name: Install new project dependencies | |
working-directory: new_android_project | |
run: flutter pub get | |
- name: Build Android APK (new project) | |
working-directory: new_android_project | |
run: flutter build apk --release | |
- name: Upload Android APK Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: android-apk | |
path: new_android_project/build/app/outputs/flutter-apk/app-release.apk |