Created
April 19, 2019 04:26
-
-
Save mileskrell/7074c10cb3298a2c9d75e733be7061c2 to your computer and use it in GitHub Desktop.
Example of declaring Android signing configs using Gradle Kotlin DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
signingConfigs { | |
getByName("debug") { | |
keyAlias = "debug" | |
keyPassword = "my debug key password" | |
storeFile = file("/home/miles/keystore.jks") | |
storePassword = "my keystore password" | |
} | |
create("release") { | |
keyAlias = "release" | |
keyPassword = "my release key password" | |
storeFile = file("/home/miles/keystore.jks") | |
storePassword = "my keystore password" | |
} | |
} | |
compileSdkVersion(28) | |
defaultConfig { | |
applicationId = "com.mileskrell.someneatapp" | |
minSdkVersion(19) | |
targetSdkVersion(28) | |
versionCode = 1 | |
versionName = "1.0" | |
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | |
} | |
buildTypes { | |
getByName("release") { | |
isMinifyEnabled = false | |
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | |
signingConfig = signingConfigs.getByName("release") | |
isDebuggable = false | |
} | |
getByName("debug") { | |
signingConfig = signingConfigs.getByName("debug") | |
isDebuggable = true | |
} | |
} | |
} |
Using keystore.properties
files (create it in project root, gitignored)
Contents of keystore.properties
storePassword=mypass
keyPassword=mypass
keyAlias=key0
In app module build.gradle.kts
...
defaultConfig {
applicationId = "com.myapp"
minSdk = 24
targetSdk = 34
versionCode = 2
versionName = "1.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties().apply {
load(FileInputStream(keystorePropertiesFile))
}
signingConfigs {
create("release") {
storeFile = file("$rootDir/keystore.jks")
storePassword = keystoreProperties["storePassword"] as String
keyAlias = keystoreProperties["keyAlias"] as String
keyPassword = keystoreProperties["keyPassword"] as String
}
}
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
isDebuggable = true
signingConfig = signingConfigs["release"]
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this man 🙏🏾🙏🏾🙏🏾