Skip to content

Commit 3f43491

Browse files
Use fastlane to distribute aab
1 parent baef6dd commit 3f43491

File tree

4 files changed

+79
-44
lines changed

4 files changed

+79
-44
lines changed

.github/workflows/ci.yaml

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,18 @@ jobs:
4040
- uses: ruby/setup-ruby@v1
4141
with:
4242
bundler-cache: true
43-
# https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md#java
44-
- name: Set java version
45-
run: |
46-
echo "JAVA_HOME=$JAVA_HOME_21_arm64" >> $GITHUB_ENV
4743
- uses: subosito/flutter-action@v2
4844
with:
4945
# This has to be kept in sync with .tool-versions
5046
flutter-version: '3.27.1'
5147
channel: 'stable'
5248
# This action takes 1m30s to finish. Enable cache to make it shorter.
5349
cache: true
54-
- run: echo "$ANDROID_HOME/tools/bin" >> $GITHUB_PATH
5550
- run: make example-flutter-pub-get
5651
- run: make example-flutter-test
5752
- run: make example-flutter-analyze
5853
- run: make example-dart-format
59-
- run: flutter build apk --debug
60-
working-directory: ./example
54+
- run: make example-build-unsigned-android-aab
6155

6256
deploy-docs:
6357
runs-on: ubuntu-24.04
@@ -127,48 +121,38 @@ jobs:
127121
deploy-android:
128122
runs-on: macos-14
129123
needs: ["test-android"]
130-
# We cannot build in PRs because secrets are not available in PRs.
131-
if: ${{ github.repository == 'authgear/authgear-sdk-flutter' && github.ref == 'refs/heads/main' }}
132-
defaults:
133-
run:
134-
working-directory: "./example"
124+
if: ${{ github.repository == 'authgear/authgear-sdk-flutter' }}
135125
steps:
136126
- uses: actions/checkout@v4
137-
- uses: actions/setup-node@v4
127+
- uses: ruby/setup-ruby@v1
138128
with:
139-
node-version-file: "./.tool-versions"
140-
# https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md#java
141-
- name: Set java version
142-
run: |
143-
echo "JAVA_HOME=$JAVA_HOME_21_arm64" >> $GITHUB_ENV
144-
- run: npm install -g appcenter-cli
129+
bundler-cache: true
145130
- uses: subosito/flutter-action@v2
146131
with:
147132
# This has to be kept in sync with .tool-versions
148133
flutter-version: '3.27.1'
149134
channel: 'stable'
150135
# This action takes 1m30s to finish. Enable cache to make it shorter.
151136
cache: true
152-
- run: flutter pub get
153-
- run: flutter test
154-
- run: flutter analyze --no-fatal-infos
155-
- run: dart format --set-exit-if-changed lib
156-
- name: Prepare key store
157-
env:
158-
ANDROID_KEY_STORE_BASE64: ${{ secrets.ANDROID_KEY_STORE_BASE64 }}
159-
run: |
160-
KEY_STORE_PATH=./android/app/keystore.jks
161-
162-
echo -n "$ANDROID_KEY_STORE_BASE64" | base64 --decode -o "$KEY_STORE_PATH"
163-
- name: Build .apk
137+
- run: make example-flutter-pub-get
138+
- run: make example-flutter-test
139+
- run: make example-flutter-analyze
140+
- run: make example-dart-format
141+
- name: Build aab
164142
env:
143+
STORE_BASE64: ${{ secrets.ANDROID_KEY_STORE_BASE64 }}
165144
STORE_PASSWORD: ${{ secrets.ANDROID_KEY_STORE_PASSWORD }}
166145
KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
167146
KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
168147
run: |
169-
BUILD_NUMBER=$(date +%s)
170-
flutter build apk --build-number $BUILD_NUMBER -P STORE_PASSWORD="$STORE_PASSWORD" -P KEY_PASSWORD="$KEY_PASSWORD" -P KEY_ALIAS="$KEY_ALIAS"
171-
- name: Distribute to App Center
148+
export STORE_FILE="$RUNNER_TEMP/upload_key.jks"
149+
echo -n "$STORE_BASE64" | base64 --decode -o "$STORE_FILE"
150+
make example-build-android-aab
151+
- name: Upload aab
152+
if: ${{ github.ref == 'refs/heads/main' }}
172153
env:
173-
APPCENTER_ACCESS_TOKEN: ${{ secrets.ANDROID_APPCENTER_ACCESS_TOKEN }}
174-
run: appcenter distribute release --debug --silent --file "./build/app/outputs/flutter-apk/app-release.apk" --group "Collaborators" --app "Oursky/Authgear-Demo-Flutter-Android"
154+
GOOGLE_SERVICE_ACCOUNT_KEY_JSON_BASE64: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY_JSON_BASE64 }}
155+
run: |
156+
export GOOGLE_SERVICE_ACCOUNT_KEY_JSON_FILE="$RUNNER_TEMP/google_service_account_key.json"
157+
echo -n "$GOOGLE_SERVICE_ACCOUNT_KEY_JSON_BASE64" | base64 --decode -o "$GOOGLE_SERVICE_ACCOUNT_KEY_JSON_FILE"
158+
make example-upload-android-aab

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ example-build-ios-app:
3030
example-upload-ios-app:
3131
bundle exec fastlane ios upload_ios_app ipa:./build/Release/iOS/Runner/Runner.ipa
3232

33+
.PHONY: example-build-unsigned-android-aab
34+
example-build-unsigned-android-aab:
35+
cd ./example/android; ./gradlew :app:bundleDebug
36+
37+
.PHONY: example-build-android-aab
38+
example-build-android-aab:
39+
bundle exec fastlane android build_aab \
40+
VERSION_CODE:$(shell date +%s) \
41+
STORE_FILE:$(STORE_FILE) \
42+
STORE_PASSWORD:$(STORE_PASSWORD) \
43+
KEY_ALIAS:$(KEY_ALIAS) \
44+
KEY_PASSWORD:$(KEY_PASSWORD)
45+
46+
.PHONY: example-upload-android-aab
47+
example-upload-android-aab:
48+
bundle exec fastlane android upload_aab \
49+
json_key:$(GOOGLE_SERVICE_ACCOUNT_KEY_JSON_FILE)
50+
3351
.PHONY: sdk-flutter-pub-get
3452
sdk-flutter-pub-get:
3553
flutter pub get

example/android/app/build.gradle

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,35 @@ android {
2424
}
2525

2626
defaultConfig {
27-
applicationId = "com.authgear.exampleapp.flutter"
27+
applicationId = "com.authgear.sdk.exampleapp.flutter"
2828
// minSdkVersion flutter.minSdkVersion
2929
// 21 is required to use androidx.security
3030
minSdk = 21
3131
targetSdk = flutter.targetSdkVersion
32-
versionCode = flutter.versionCode
32+
if (project.hasProperty("VERSION_CODE")) {
33+
versionCode = Integer.parseInt(project.findProperty("VERSION_CODE"))
34+
} else {
35+
versionCode = flutter.versionCode
36+
}
3337
versionName = flutter.versionName
3438
}
3539

3640
signingConfigs {
37-
release {
38-
storeFile file("keystore.jks")
39-
storePassword project.ext.has("STORE_PASSWORD") ? project.ext["STORE_PASSWORD"] : ""
40-
keyAlias project.ext.has("KEY_ALIAS") ? project.ext["KEY_ALIAS"] : ""
41-
keyPassword project.ext.has("KEY_PASSWORD") ? project.ext["KEY_PASSWORD"] : ""
41+
if (project.hasProperty("STORE_FILE")) {
42+
release {
43+
storeFile file(project.findProperty("STORE_FILE"))
44+
storePassword project.findProperty("STORE_PASSWORD")
45+
keyAlias project.findProperty("KEY_ALIAS")
46+
keyPassword project.findProperty("KEY_PASSWORD")
47+
}
4248
}
4349
}
4450

4551
buildTypes {
4652
release {
47-
signingConfig signingConfigs.release
53+
if (project.hasProperty("STORE_FILE")) {
54+
signingConfig signingConfigs.release
55+
}
4856
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
4957
}
5058
}

fastlane/Fastfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,28 @@ platform :ios do
2626
)
2727
end
2828
end
29+
30+
platform :android do
31+
lane :build_aab do |options|
32+
gradle(
33+
project_dir: "./example/android",
34+
tasks: [":app:bundleRelease"],
35+
properties: {
36+
"VERSION_CODE" => options[:VERSION_CODE],
37+
"STORE_FILE" => options[:STORE_FILE],
38+
"STORE_PASSWORD" => options[:STORE_PASSWORD],
39+
"KEY_ALIAS" => options[:KEY_ALIAS],
40+
"KEY_PASSWORD" => options[:KEY_PASSWORD],
41+
},
42+
)
43+
end
44+
45+
lane :upload_aab do |options|
46+
upload_to_play_store(
47+
json_key: options[:json_key],
48+
package_name: "com.authgear.sdk.exampleapp.flutter",
49+
track: "internal",
50+
aab: "./example/build/app/outputs/bundle/release/app-release.aab",
51+
)
52+
end
53+
end

0 commit comments

Comments
 (0)