-
Notifications
You must be signed in to change notification settings - Fork 45
Configure android gradle release build type #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,20 @@ | ||||||||||||||||||||||||||||||||||||||||
| import java.util.Properties | ||||||||||||||||||||||||||||||||||||||||
| import java.io.FileInputStream | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| plugins { | ||||||||||||||||||||||||||||||||||||||||
| id("com.android.application") | ||||||||||||||||||||||||||||||||||||||||
| id("kotlin-android") | ||||||||||||||||||||||||||||||||||||||||
| // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. | ||||||||||||||||||||||||||||||||||||||||
| id("dev.flutter.flutter-gradle-plugin") | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| val keystorePropertiesFile = rootProject.file("key.properties") | ||||||||||||||||||||||||||||||||||||||||
| val keystoreProperties = Properties().apply { | ||||||||||||||||||||||||||||||||||||||||
| if (keystorePropertiesFile.exists()) { | ||||||||||||||||||||||||||||||||||||||||
| load(FileInputStream(keystorePropertiesFile)) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| android { | ||||||||||||||||||||||||||||||||||||||||
| namespace = "dev.shtanko.flutter_bloc_app_template" | ||||||||||||||||||||||||||||||||||||||||
| compileSdk = flutter.compileSdkVersion | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -59,11 +69,27 @@ android { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| signingConfigs { | ||||||||||||||||||||||||||||||||||||||||
| register("release") { | ||||||||||||||||||||||||||||||||||||||||
| enableV1Signing = true | ||||||||||||||||||||||||||||||||||||||||
| enableV2Signing = true | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| storeFile = keystoreProperties["storeFile"]?.let { file(it) } | ||||||||||||||||||||||||||||||||||||||||
| storePassword = keystoreProperties["storePassword"] as String? | ||||||||||||||||||||||||||||||||||||||||
| keyAlias = keystoreProperties["keyAlias"] as String? | ||||||||||||||||||||||||||||||||||||||||
| keyPassword = keystoreProperties["keyPassword"] as String? | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| buildTypes { | ||||||||||||||||||||||||||||||||||||||||
| release { | ||||||||||||||||||||||||||||||||||||||||
| // TODO: Add your own signing config for the release build. | ||||||||||||||||||||||||||||||||||||||||
| // Signing with the debug keys for now, so `flutter run --release` works. | ||||||||||||||||||||||||||||||||||||||||
| signingConfig = signingConfigs.getByName("debug") | ||||||||||||||||||||||||||||||||||||||||
| isMinifyEnabled = true | ||||||||||||||||||||||||||||||||||||||||
| isShrinkResources = true | ||||||||||||||||||||||||||||||||||||||||
| proguardFiles( | ||||||||||||||||||||||||||||||||||||||||
| getDefaultProguardFile("proguard-android-optimize.txt"), | ||||||||||||||||||||||||||||||||||||||||
| "proguard-rules.pro" | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| signingConfig = signingConfigs.getByName("release") | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
93
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t hard-fail local release builds when key.properties is absent; gate signing or scope it to prod flavor. As-is, devRelease/qaRelease will require real signing keys. Prefer a conditional fallback to debug signing locally (or assign release signing only to prod flavor). Option A (inline fallback): - signingConfig = signingConfigs.getByName("release")
+ signingConfig = if (keystorePropertiesFile.exists())
+ signingConfigs.getByName("release")
+ else
+ signingConfigs.getByName("debug")Option B (scope to prod flavor): - buildTypes {
- release {
+ buildTypes {
+ release {
...
- signingConfig = signingConfigs.getByName("release")
+ }
+ }
+ productFlavors {
+ // existing dev/qa/prod...
+ getByName("prod") {
+ signingConfig = signingConfigs.getByName("release")
}
}Also verify that proguard-rules.pro exists and includes any Flutter/reflective keep rules to avoid runtime crashes after minification. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use create(...) instead of register(...) for signingConfigs; add v3/v4 signing; tighten property reads.
register may not be supported on this container and can fail to configure the signing config. Also enable V3/V4 signing and use getProperty for typed reads.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents