Skip to content

Commit f1706e2

Browse files
brownpub1shglkdhngx3hrnhf4gf8vhpqdrmeludctechdvpwd3988zzs7ncq2cmtxu
andauthored
BOT-1247 Configure Android Play identity and signing (#1829)
Signed-off-by: npub1shglkdhngx3hrnhf4gf8vhpqdrmeludctechdvpwd3988zzs7ncq2cmtxu <85d1fb36f341a371cee9aa12765c2068f79ff1b85e7176b02e6c4a738850f4f0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1shglkdhngx3hrnhf4gf8vhpqdrmeludctechdvpwd3988zzs7ncq2cmtxu <85d1fb36f341a371cee9aa12765c2068f79ff1b85e7176b02e6c4a738850f4f0@sprout-oss.stage.blox.sqprod.co>
1 parent ffa2de0 commit f1706e2

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

‎mobile/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ flutter test
2929

3030
Or from the repo root: `just mobile-check` and `just mobile-test`.
3131

32+
## Android release signing
33+
34+
Android release builds fail unless all upload-key inputs are supplied through the
35+
environment:
36+
37+
- `BUZZ_ANDROID_UPLOAD_KEYSTORE_PATH`: path to a CI-vended keystore file
38+
- `BUZZ_ANDROID_UPLOAD_KEYSTORE_PASSWORD`
39+
- `BUZZ_ANDROID_UPLOAD_KEY_ALIAS`
40+
- `BUZZ_ANDROID_UPLOAD_KEY_PASSWORD`
41+
42+
The keystore path must be absolute, and the keystore must remain outside the
43+
repository. Development and debug builds do not require these variables.
44+
3245
## Architecture
3346

3447
```

‎mobile/android/app/build.gradle.kts‎

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ plugins {
55
id("dev.flutter.flutter-gradle-plugin")
66
}
77

8+
val uploadKeystorePath = providers.environmentVariable("BUZZ_ANDROID_UPLOAD_KEYSTORE_PATH").orNull
9+
val uploadKeystorePassword = providers.environmentVariable("BUZZ_ANDROID_UPLOAD_KEYSTORE_PASSWORD").orNull
10+
val uploadKeyAlias = providers.environmentVariable("BUZZ_ANDROID_UPLOAD_KEY_ALIAS").orNull
11+
val uploadKeyPassword = providers.environmentVariable("BUZZ_ANDROID_UPLOAD_KEY_PASSWORD").orNull
12+
val uploadSigningValues =
13+
mapOf(
14+
"BUZZ_ANDROID_UPLOAD_KEYSTORE_PATH" to uploadKeystorePath,
15+
"BUZZ_ANDROID_UPLOAD_KEYSTORE_PASSWORD" to uploadKeystorePassword,
16+
"BUZZ_ANDROID_UPLOAD_KEY_ALIAS" to uploadKeyAlias,
17+
"BUZZ_ANDROID_UPLOAD_KEY_PASSWORD" to uploadKeyPassword,
18+
)
19+
val missingUploadSigningValues = uploadSigningValues.filterValues { it.isNullOrBlank() }.keys
20+
val hasUploadSigning = missingUploadSigningValues.isEmpty()
21+
822
android {
9-
namespace = "com.buzz.buzz_mobile"
23+
namespace = "xyz.block.buzz.mobile"
1024
compileSdk = flutter.compileSdkVersion
1125
ndkVersion = flutter.ndkVersion
1226

@@ -20,8 +34,7 @@ android {
2034
}
2135

2236
defaultConfig {
23-
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
24-
applicationId = "com.buzz.buzz_mobile"
37+
applicationId = "xyz.block.buzz.mobile"
2538
// You can update the following values to match your application needs.
2639
// For more information, see: https://flutter.dev/to/review-gradle-config.
2740
minSdk = flutter.minSdkVersion
@@ -30,11 +43,54 @@ android {
3043
versionName = flutter.versionName
3144
}
3245

46+
signingConfigs {
47+
if (hasUploadSigning) {
48+
create("upload") {
49+
storeFile = file(requireNotNull(uploadKeystorePath))
50+
storePassword = uploadKeystorePassword
51+
keyAlias = uploadKeyAlias
52+
keyPassword = uploadKeyPassword
53+
}
54+
}
55+
}
56+
3357
buildTypes {
3458
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")
59+
if (hasUploadSigning) {
60+
signingConfig = signingConfigs.getByName("upload")
61+
}
62+
}
63+
}
64+
}
65+
66+
gradle.taskGraph.whenReady {
67+
val buildsRelease = allTasks.any { task ->
68+
task.project == project && task.name in setOf("assembleRelease", "bundleRelease")
69+
}
70+
if (buildsRelease && !hasUploadSigning) {
71+
throw GradleException(
72+
"Release builds require Android upload signing credentials. Missing: " +
73+
missingUploadSigningValues.sorted().joinToString(", "),
74+
)
75+
}
76+
if (buildsRelease) {
77+
val configuredKeystore = File(requireNotNull(uploadKeystorePath))
78+
if (!configuredKeystore.isAbsolute) {
79+
throw GradleException(
80+
"BUZZ_ANDROID_UPLOAD_KEYSTORE_PATH must be absolute: $configuredKeystore",
81+
)
82+
}
83+
val keystore = file(configuredKeystore)
84+
val repositoryRoot = rootProject.projectDir.parentFile.parentFile.canonicalFile
85+
if (keystore.canonicalFile.toPath().startsWith(repositoryRoot.toPath())) {
86+
throw GradleException(
87+
"BUZZ_ANDROID_UPLOAD_KEYSTORE_PATH must be outside the repository: $keystore",
88+
)
89+
}
90+
if (!keystore.isFile || !keystore.canRead()) {
91+
throw GradleException(
92+
"BUZZ_ANDROID_UPLOAD_KEYSTORE_PATH is not a readable file: $keystore",
93+
)
3894
}
3995
}
4096
}

‎mobile/android/app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.INTERNET" />
23
<uses-permission android:name="android.permission.CAMERA" />
34
<application
45
android:label="Buzz"

mobile/android/app/src/main/kotlin/com/buzz/buzz_mobile/MainActivity.kt renamed to mobile/android/app/src/main/kotlin/xyz/block/buzz/mobile/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.buzz.buzz_mobile
1+
package xyz.block.buzz.mobile
22

33
import android.graphics.Bitmap
44
import android.graphics.BitmapFactory

0 commit comments

Comments
 (0)