Build & Release
Hướng dẫn build app production và upload lên Google Play Store và Apple App Store.
Chuẩn bị
- Bundle đã tạo trong Mobile Center
configs.jsonđã tải về và đặt đúng vị trí- Signing keys đã chuẩn bị
Quan trọng: Không sửa thủ công
configs.json— luôn tải lại từ Mobile Center khi cần thay đổi cấu hình.
Build Android
Bước 1: Tạo signing key
keytool -genkey -v \
-keystore ~/vielang-release.keystore \
-alias vielang \
-keyalg RSA -keysize 2048 \
-validity 10000Bước 2: Cấu hình signing
Tạo file android/key.properties:
storePassword=YOUR_STORE_PASSWORD
keyPassword=YOUR_KEY_PASSWORD
keyAlias=vielang
storeFile=/Users/yourname/vielang-release.keystoreBảo mật: Thêm
key.propertiesvào.gitignore.
Cập nhật android/app/build.gradle:
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
}
}
}Bước 3: Build
# App Bundle (khuyến nghị cho Google Play)
flutter build appbundle \
--no-tree-shake-icons \
--dart-define-from-file configs.json
# Output: build/app/outputs/bundle/release/app-release.aab
# APK (nếu cần)
flutter build apk \
--no-tree-shake-icons \
--dart-define-from-file configs.json \
--split-per-abiBước 4: Upload lên Google Play
- Google Play Console → App của bạn
- Release → Production → Create new release
- Upload file
.aab - Điền release notes
- Submit for review
Build iOS
Yêu cầu
- macOS với Xcode 15+
- Apple Developer Account ($99/năm)
- Provisioning profiles và certificates
Bước 1: Cấu hình Xcode
open ios/Runner.xcworkspaceTrong Xcode:
- Runner → Signing & Capabilities
- Chọn Team (Apple Developer Account)
- Bundle Identifier:
com.yourcompany.app - Đảm bảo Automatically manage signing được bật
Bước 2: Build
flutter build ipa \
--no-tree-shake-icons \
--dart-define-from-file configs.json
# Output: build/ios/ipa/YOUR_APP.ipaBước 3: Upload lên App Store
Dùng Transporter (macOS):
- Tải Transporter từ App Store
- Drag & drop file
.ipa - Click Deliver
Dùng xcrun:
xcrun altool --upload-app \
--type ios \
--file "build/ios/ipa/YOUR_APP.ipa" \
--username "your@apple.id" \
--password "app-specific-password"Bước 4: Submit trên App Store Connect
- App Store Connect
- App của bạn → TestFlight (test) hoặc App Store (production)
- Chọn build vừa upload
- Submit for Review
CI/CD với GitHub Actions
.github/workflows/release.yml:
name: Release
on:
push:
tags: ['v*']
jobs:
build-android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.29.0'
- name: Write configs
run: echo '${{ secrets.CONFIGS_JSON }}' > configs.json
- name: Write keystore
run: |
echo '${{ secrets.KEYSTORE_BASE64 }}' | base64 -d > android/app/release.keystore
echo 'storeFile=release.keystore' > android/key.properties
echo 'storePassword=${{ secrets.KEY_STORE_PASSWORD }}' >> android/key.properties
echo 'keyAlias=${{ secrets.KEY_ALIAS }}' >> android/key.properties
echo 'keyPassword=${{ secrets.KEY_PASSWORD }}' >> android/key.properties
- run: flutter pub get
- run: flutter build appbundle --no-tree-shake-icons --dart-define-from-file configs.json
- uses: actions/upload-artifact@v4
with:
name: android-release
path: build/app/outputs/bundle/release/app-release.aabBuild Flags quan trọng
| Flag | Lý do bắt buộc |
|---|---|
--dart-define-from-file configs.json | Nạp cấu hình backend, OAuth2, app secret |
--no-tree-shake-icons | Giữ lại icon font cho notification icons |
Checklist trước khi release
-
configs.jsonđã tải mới nhất từ Mobile Center - Version code và version name đã cập nhật trong
pubspec.yaml - Icon và splash screen đã thay thế
- Push notification đã test
- OAuth2 đã test (nếu dùng)
- Deep link QR code đã test
- Build thành công không warning
- Test trên thiết bị thật (cả Android và iOS)