Skip to content

Commit b96956d

Browse files
android signing
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent b799580 commit b96956d

3 files changed

Lines changed: 71 additions & 11 deletions

File tree

.github/workflows/build-multi-platform.yml

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
workflow_dispatch:
55
push:
66
branches: ["master"]
7+
tags: ["v*"]
78

89
jobs:
910
build-desktop:
@@ -64,9 +65,11 @@ jobs:
6465
path: ${{ matrix.platform.artifact_path }}
6566
if-no-files-found: error
6667

67-
build-android:
68-
name: Build android
68+
build-android-release:
69+
name: Build signed android apk
6970
runs-on: ubuntu-latest
71+
if: startsWith(github.ref, 'refs/tags/v')
72+
environment: release
7073

7174
steps:
7275
- name: Checkout
@@ -87,17 +90,43 @@ jobs:
8790
- name: Get dependencies
8891
run: flutter pub get
8992

90-
- name: Build Android APK
93+
- name: Restore Android keystore
94+
run: |
95+
echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > android/release-keystore.jks
96+
97+
- name: Create key.properties
98+
run: |
99+
cat > android/key.properties <<EOF
100+
storePassword=${{ secrets.ANDROID_STORE_PASSWORD }}
101+
keyPassword=${{ secrets.ANDROID_KEY_PASSWORD }}
102+
keyAlias=${{ secrets.ANDROID_KEY_ALIAS }}
103+
storeFile=release-keystore.jks
104+
EOF
105+
106+
- name: Build signed Android APK
91107
run: flutter build apk --release
92108

93-
- name: Build Android App Bundle
94-
run: flutter build appbundle --release
109+
- name: Verify APK signature
110+
run: |
111+
BUILD_TOOLS_VERSION=$(ls "$ANDROID_HOME/build-tools" | sort -V | tail -n 1)
112+
"$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/apksigner" verify --print-certs build/app/outputs/flutter-apk/app-release.apk
113+
114+
- name: Generate checksums
115+
run: |
116+
sha256sum build/app/outputs/flutter-apk/app-release.apk > build/app/outputs/flutter-apk/app-release.apk.sha256
117+
118+
- name: Export signing certificate details
119+
run: |
120+
BUILD_TOOLS_VERSION=$(ls "$ANDROID_HOME/build-tools" | sort -V | tail -n 1)
121+
"$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/apksigner" verify --print-certs build/app/outputs/flutter-apk/app-release.apk \
122+
> build/app/outputs/flutter-apk/app-release.cert.txt
95123
96124
- name: Upload Android artifact
97125
uses: actions/upload-artifact@v4
98126
with:
99-
name: ailurus-android
127+
name: ailurus-android-signed
100128
path: |
101-
build/app/outputs/flutter-apk/*.apk
102-
build/app/outputs/bundle/release/*.aab
129+
build/app/outputs/flutter-apk/app-release.apk
130+
build/app/outputs/flutter-apk/app-release.apk.sha256
131+
build/app/outputs/flutter-apk/app-release.cert.txt
103132
if-no-files-found: error

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ app.*.map.json
4848
/lib/generated/
4949
/android/.gradle/
5050
/android/local.properties
51+
/android/key.properties
52+
/android/release-keystore.jks
5153
/ios/Flutter/ephemeral/
5254
/macos/Flutter/ephemeral/
5355
/linux/flutter/ephemeral/

android/app/build.gradle.kts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1+
import java.io.FileInputStream
2+
import java.util.Properties
3+
14
plugins {
25
id("com.android.application")
36
id("kotlin-android")
47
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
58
id("dev.flutter.flutter-gradle-plugin")
69
}
710

11+
val keystoreProperties = Properties()
12+
val keystorePropertiesFile = rootProject.file("key.properties")
13+
val hasKeystoreProperties = keystorePropertiesFile.exists()
14+
val isReleaseBuildRequested = gradle.startParameter.taskNames.any {
15+
it.contains("Release", ignoreCase = true)
16+
}
17+
18+
if (hasKeystoreProperties) {
19+
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
20+
} else if (isReleaseBuildRequested) {
21+
throw GradleException(
22+
"Missing android/key.properties. Configure release signing before building release artifacts.",
23+
)
24+
}
25+
826
android {
927
namespace = "com.example.ailurus"
1028
compileSdk = flutter.compileSdkVersion
@@ -30,11 +48,22 @@ android {
3048
versionName = flutter.versionName
3149
}
3250

51+
signingConfigs {
52+
if (hasKeystoreProperties) {
53+
create("release") {
54+
keyAlias = keystoreProperties["keyAlias"] as String
55+
keyPassword = keystoreProperties["keyPassword"] as String
56+
storeFile = file(keystoreProperties["storeFile"] as String)
57+
storePassword = keystoreProperties["storePassword"] as String
58+
}
59+
}
60+
}
61+
3362
buildTypes {
3463
release {
35-
// TODO: Add your own signing config for the release build.
36-
// Signing with the debug keys for now, so `flutter run --release` works.
37-
signingConfig = signingConfigs.getByName("debug")
64+
if (hasKeystoreProperties) {
65+
signingConfig = signingConfigs.getByName("release")
66+
}
3867
}
3968
}
4069
}

0 commit comments

Comments
 (0)