build(android): configure release signing with keystore

Replaces default debug signing with a dedicated release keystore loaded via android/key.properties. Fixes the cross-host signature mismatch that broke adb install -r. keystore and key.properties are gitignored (signing identity must not be committed).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-08-10 13:43:29 +08:00
parent 99ed3bb9ec
commit a702f80116
2 changed files with 23 additions and 3 deletions

4
.gitignore vendored
View File

@@ -46,6 +46,10 @@ app.*.map.json
/android/app/release /android/app/release
/android/build/ /android/build/
# Release signing keystore (do NOT commit — contains signing identity)
/android/key.properties
/android/app/key.jks
# AI Agents # AI Agents
.claude/ .claude/
.agents/ .agents/

View File

@@ -1,3 +1,6 @@
import java.util.Properties
import java.io.FileInputStream
plugins { plugins {
id("com.android.application") id("com.android.application")
id("kotlin-android") id("kotlin-android")
@@ -5,11 +8,26 @@ plugins {
id("dev.flutter.flutter-gradle-plugin") id("dev.flutter.flutter-gradle-plugin")
} }
val keystoreProperties = Properties()
val keystorePropertiesFile = rootProject.file("key.properties")
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
android { android {
namespace = "com.example.pad_scanner" namespace = "com.example.pad_scanner"
compileSdk = flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion ndkVersion = flutter.ndkVersion
signingConfigs {
create("release") {
keyAlias = keystoreProperties["keyAlias"] as String
keyPassword = keystoreProperties["keyPassword"] as String
storeFile = file(keystoreProperties["storeFile"] as String)
storePassword = keystoreProperties["storePassword"] as String
}
}
compileOptions { compileOptions {
sourceCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11
@@ -32,9 +50,7 @@ android {
buildTypes { buildTypes {
release { release {
// TODO: Add your own signing config for the release build. signingConfig = signingConfigs.getByName("release")
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
} }
} }
} }