mobile-eda/docs/BUILD_GUIDE.md

7.3 KiB

Mobile EDA 打包指南

版本: v1.1.0
最后更新: 2026-03-07


📋 环境要求

通用要求

  • Flutter SDK >= 3.19.0
  • Dart SDK >= 3.0.0
  • Git

Android 打包

  • Android SDK 30+
  • JDK 11+
  • Android Studio (推荐)

Windows 打包

  • Windows 10/11
  • Visual Studio 2019+ (带 C++ 桌面开发)
  • Windows 10 SDK

Linux 打包

  • Ubuntu 20.04+ / Debian 11+ / Fedora 35+
  • Clang/CMake/Ninja
  • pkg-config
  • GTK+3

🚀 快速开始

1. 获取依赖

cd mobile-eda
flutter pub get

2. 运行测试

flutter test

3. 构建

方式 A: 全平台构建 (推荐)

# Linux/macOS
./scripts/build-all.sh

# Windows (PowerShell)
.\scripts\build-windows.ps1

方式 B: 单独平台构建

# Android APK
flutter build apk --release

# Windows EXE
flutter build windows --release

# Linux
flutter build linux --release

# Web
flutter build web --release

📦 输出文件

Android

文件 说明 大小
mobile-eda-v1.1.0-debug.apk Debug 版本 ~50MB
mobile-eda-v1.1.0-release.apk Release 版本 ~25MB
mobile-eda-v1.1.0.aab Google Play Bundle ~20MB

Windows

文件 说明 大小
mobile-eda.exe 主程序 ~15MB
flutter_windows.dll Flutter 运行时 ~10MB
*.dll 依赖库 ~20MB
总计 完整包 ~50MB

Linux

文件 说明
mobile_eda 主程序
lib/ 依赖库
data/ 资源文件

Web

文件 说明
index.html 入口页面
main.dart.js 编译后的 JS
assets/ 静态资源

🔧 详细步骤

Android 打包

1. 配置签名

创建 android/key.properties:

storePassword=你的密钥库密码
keyPassword=你的密钥密码
keyAlias=上传
storeFile=../upload-keystore.jks

2. 修改 android/app/build.gradle

android {
    ...
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

3. 构建

# 生成密钥库 (首次)
keytool -genkey -v -keystore upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload

# 构建 Release APK
flutter build apk --release

# 构建 App Bundle (Google Play)
flutter build appbundle --release

4. 安装测试

# 查看设备
adb devices

# 安装 APK
adb install build/app/outputs/flutter-apk/app-release.apk

Windows 打包

1. 安装 Visual Studio

2. 构建

# PowerShell
flutter build windows --release

# 或使用脚本
.\scripts\build-windows.ps1

3. 创建安装包

# 进入构建目录
cd build\windows\runner\Release

# 复制所有文件到发布目录
mkdir mobile-eda-v1.1.0
copy * mobile-eda-v1.1.0\

# 压缩
Compress-Archive -Path mobile-eda-v1.1.0\* -DestinationPath mobile-eda-v1.1.0-windows-x64.zip

4. 创建快捷方式 (可选)

使用 Inno Setup 创建安装程序:

[Setup]
AppName=Mobile EDA
AppVersion=1.1.0
DefaultDirName={pf}\MobileEDA
DefaultGroupName=Mobile EDA
OutputDir=installer

[Files]
Source: "build\windows\runner\Release\*"; DestDir: "{app}"

[Icons]
Name: "{group}\Mobile EDA"; Filename: "{app}\mobile_eda.exe"

Linux 打包

1. 安装依赖

# Ubuntu/Debian
sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev

# Fedora
sudo dnf install clang cmake ninja-build pkg-config gtk3-devel

2. 构建

flutter build linux --release

3. 创建 AppImage (可选)

# 安装 linuxdeploy
wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
chmod +x linuxdeploy-x86_64.AppImage

# 创建 AppImage
./linuxdeploy-x86_64.AppImage --appdir AppDir -e build/linux/x64/release/bundle/mobile_eda -d mobile-eda.desktop -i icons/mobile_eda.png --output appimage

4. 创建 DEB 包 (可选)

# 使用 flutter_debianizer
flutter pub add dev:flutter_debianizer
flutter debianize
cd debian
dpkg-buildpackage -us -uc -b

Web 打包

1. 构建

flutter build web --release

2. 部署

GitHub Pages:

# 安装 deploy_to_github
flutter pub add deploy_to_github

# 部署
flutter pub run deploy_to_github

Netlify:

# 安装 Netlify CLI
npm install -g netlify-cli

# 部署
netlify deploy --prod --dir=build/web

Vercel:

# 安装 Vercel CLI
npm install -g vercel

# 部署
vercel --prod

📊 文件大小优化

减少 APK 大小

# 启用代码压缩
# android/app/build.gradle
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
    }
}

# 只保留需要的语言
# android/app/build.gradle
android {
    defaultConfig {
        resConfigs "en", "zh"
    }
}

减少 Windows 大小

# 使用 flutter build windows --split-debug-info
flutter build windows --release --split-debug-info=symbols

# 压缩 DLL
upx --best *.dll

🔍 常见问题

Q: Android 构建失败 "SDK not found"

A: 确保 ANDROID_HOME 环境变量已设置

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Q: Windows 构建失败 "Visual Studio not found"

A: 安装 Visual Studio 2019+ 并选择 "使用 C++ 的桌面开发"

Q: Linux 构建失败 "GTK not found"

A: 安装 GTK+3 开发库

sudo apt-get install libgtk-3-dev

Q: Web 构建后白屏

A: 检查 baseHref 配置

flutter build web --base-href /your-repo-name/

📈 性能基准

平台 启动时间 内存占用 包大小
Android <2s ~150MB 25MB
Windows <3s ~200MB 50MB
Linux <2s ~180MB 45MB
Web <5s ~100MB 5MB (gzip)

📝 发布清单

Android (Google Play)

  • 签名配置
  • App Bundle 构建
  • 隐私政策
  • 应用截图
  • 描述文案
  • 提交审核

Windows (官网下载)

  • 代码签名证书 (可选)
  • 安装包制作
  • 官网下载页
  • 更新机制

Linux (Snap/Flatpak)

  • Snapcraft 配置
  • Flatpak 清单
  • 提交到商店

Web (在线使用)

  • 域名配置
  • HTTPS 证书
  • CDN 加速
  • SEO 优化

🔗 相关链接


文档版本: v1.0
最后更新: 2026-03-07