建置指令
Flutter 支援從同一程式碼庫建置多個平台的應用程式。以下是各平台的建置指令:
# Android APK(通用)
flutter build apk
# Android App Bundle(Play Store 推薦)
flutter build appbundle
# iOS(需要 macOS + Xcode)
flutter build ios
# Web
flutter build web
# macOS(需要 macOS + Xcode)
flutter build macos
# Windows
flutter build windows
Android 部署
APK 建置
# 產生 release APK
flutter build apk --release
# 輸出位置:
# build/app/outputs/flutter-apk/app-release.apk
App Bundle 建置(Play Store)
# 產生 AAB(Google Play 推薦格式)
flutter build appbundle --release
# 輸出位置:
# build/app/outputs/bundle/release/app-release.aab
Play Store 上架步驟
- 在 Google Play Console 建立應用程式
- 設定簽名金鑰(keystore)
- 上傳 AAB 檔案
- 填寫商店資訊、螢幕截圖、內容分級
- 提交審核
iOS 部署
建置步驟
# 建置 iOS release
flutter build ios --release
# 開啟 Xcode 進行 archive
open ios/Runner.xcworkspace
App Store 上架步驟
- 在 Xcode 中選擇 Product → Archive
- 在 Organizer 中選擇 Distribute App
- 選擇 App Store Connect
- 在 App Store Connect 填寫應用資訊
- 提交審核
Web 部署
# 建置 Web 版本
flutter build web
# 輸出位置:
# build/web/
# 部署至任何靜態檔案伺服器
# 例如 Nginx、Apache、Firebase Hosting、GitHub Pages
Web 版本產生的是靜態檔案(HTML、CSS、JS),可以部署到任何支援靜態檔案的伺服器。
Nginx 設定範例
server {
listen 80;
server_name your-domain.com;
root /var/www/idempiere-mobile/build/web;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
macOS / Windows 部署
# macOS
flutter build macos --release
# 輸出: build/macos/Build/Products/Release/
# Windows
flutter build windows --release
# 輸出: build/windows/x64/runner/Release/
白牌設定(White-Label)
iDempiere Mobile 支援透過伺服器端的 AD_SysConfig 設定項進行白牌客製化,無需修改 App 程式碼:
| 設定鍵 | 預設值 | 說明 |
|---|---|---|
MOBILE_APP_NAME |
iDempiere Mobile | App 標題列顯示的名稱 |
MOBILE_SEED_COLOR |
2196F3 | Material 3 主題色彩種子值(hex 色碼) |
MOBILE_FEATURE_CHAT |
Y | 啟用/停用聊天模組 |
MOBILE_FEATURE_BOOKING |
Y | 啟用/停用預約模組 |
MOBILE_FEATURE_ATTENDANCE |
Y | 啟用/停用出勤模組 |
這些設定由 BrandingConfig 在登入後從伺服器載入,自動套用到 App 的外觀和功能開關。
Material 3 色彩種子
MOBILE_SEED_COLOR 使用 hex 色碼(不含 #),Flutter 的 ColorScheme.fromSeed() 會自動產生完整的色彩方案。例如:
2196F3— 藍色(預設)4CAF50— 綠色FF5722— 橘紅色9C27B0— 紫色
Firebase 設定(選用)
推播通知功能需要 Firebase Cloud Messaging (FCM) 設定。應用程式在缺少 Firebase 設定時仍可正常運作 — FCM 功能會優雅地停用。
設定步驟
- 在 Firebase Console 建立專案
- 為各平台新增應用程式(iOS、Android、Web)
- 下載設定檔:
- Android:
google-services.json→android/app/ - iOS:
GoogleService-Info.plist→ios/Runner/
- Android:
- 應用程式會在啟動時自動初始化 Firebase 並註冊 FCM token
FCM Token 管理
// ApiClient 提供 FCM token 註冊/取消註冊:
await api.registerFcmToken(token);
await api.unregisterFcmToken(token);
疑難排解
| 症狀 | 原因 | 解決方案 |
|---|---|---|
DioException [connection error] |
API base URL 錯誤或伺服器無法連線 | 確認 baseUrl 設定正確,伺服器已啟動 |
XMLHttpRequest onError(Web) |
iDempiere 伺服器未設定 CORS | 在 iDempiere 設定 CORS 標頭或使用反向代理 |
invalid_annotation_target 警告 |
freezed + json_serializable 已知問題 | 已在 analysis_options.yaml 中抑制 |
Locator 模糊匯入 |
與 state_notifier 的名稱衝突 | 對 flutter_riverpod 匯入加上 hide Locator |
xcodebuild not found |
僅安裝了 Xcode CLI 工具 | 從 App Store 安裝完整版 Xcode |
| 產生的檔案遺失 | 修改模型後未執行 build_runner | 執行 dart run build_runner build --delete-conflicting-outputs |
| 白牌設定未生效 | AD_SysConfig 尚未設定 | 在 iDempiere 的 AD_SysConfig 中新增對應的 key |
| 推播通知無作用 | Firebase 設定檔遺失 | 確認 google-services.json / GoogleService-Info.plist 已放置正確 |
| iOS 模擬器建置失敗 | CocoaPods 版本過舊 | 執行 cd ios && pod install --repo-update |
| Android Gradle 建置失敗 | Gradle 版本不符 | 確認 android/gradle/wrapper/gradle-wrapper.properties 版本 |
🌐 English Version
Build Commands
flutter build apk # Android APK
flutter build appbundle # Android AAB (Play Store)
flutter build ios # iOS (requires macOS + Xcode)
flutter build web # Web (static files)
flutter build macos # macOS
flutter build windows # Windows
Android Deployment
Build with flutter build appbundle --release for Play Store. Upload the AAB to Google Play Console.
iOS Deployment
Build with flutter build ios --release, then archive in Xcode and distribute to App Store Connect.
Web Deployment
Build with flutter build web. Deploy the static files in build/web/ to any web server (Nginx, Apache, Firebase Hosting, etc.).
White-Label Configuration
Customize the app via iDempiere AD_SysConfig keys — no code changes needed:
| Key | Default | Description |
|---|---|---|
MOBILE_APP_NAME |
iDempiere Mobile | App bar title |
MOBILE_SEED_COLOR |
2196F3 | Material 3 theme seed color (hex) |
MOBILE_FEATURE_CHAT |
Y | Enable/disable chat module |
MOBILE_FEATURE_BOOKING |
Y | Enable/disable booking module |
MOBILE_FEATURE_ATTENDANCE |
Y | Enable/disable attendance module |
Firebase Setup (Optional)
Push notifications require Firebase Cloud Messaging (FCM). The app works without Firebase — FCM features are gracefully disabled. To enable:
- Create a Firebase project
- Add apps for each platform
- Download config files (
google-services.jsonfor Android,GoogleService-Info.plistfor iOS)
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
DioException [connection error] |
Wrong API URL or server unreachable | Update baseUrl |
XMLHttpRequest onError (web) |
CORS not configured | Add CORS headers to iDempiere |
Locator ambiguous import |
Name conflict with state_notifier | Add hide Locator to riverpod import |
| Generated files missing | build_runner not run | Run dart run build_runner build |
| Push notifications not working | Firebase config missing | Add Firebase config files to the project |
| iOS build failure | CocoaPods outdated | Run cd ios && pod install --repo-update |