-
-
Save mileskrell/7074c10cb3298a2c9d75e733be7061c2 to your computer and use it in GitHub Desktop.
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 | |
} | |
} | |
} |
or you can define it using gradle.properties so that your CI/CD pipline give the property value for that environment and you define it locally for your machine.
@jharman-notion Right :)
@RahulSDeshpande @jharman-notion yep! that's right. (btw, how did you both stumble across this at the same time? did someone link to it somewhere? π)
It's the top search result in google for 'signing configs android kts' and I was looking for an example when converting my build files to kts.
Yes, same here ππππ
Hi, I am using kotlin dsl and in build.gradle.kts file i'm getting the key store values from properties file but i am facing the issue unable to read the keystore file location. Please help out this, how to give customized key store location.
Currently it takes default location.
How are you reading from the properties file?
This is working for me
val KEYSTORE_FILE: String by project //loads the absolute file path from properties (has to be in properties as KEYSTORE_FILE=/my/path
create("release") {
storeFile = file(KEYSTORE_FILE)
}
How are you reading from the properties file?
This is working for me
val KEYSTORE_FILE: String by project //loads the absolute file path from properties (has to be in properties as KEYSTORE_FILE=/my/path create("release") { storeFile = file(KEYSTORE_FILE) }
working successfully.
if you don't mind, please explain how to generate a key from the command line, I am tired of with it.
I haven't tried this yet but this might help with CI/CD pipelines:
file("${System.getProperty("user.home")}/exampleKeyStore.jks")
Thanks for sharing this man ππΎππΎππΎ
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
}
...
Thanks for sharing the snippet.
But line
storeFile = file("/home/miles/keystore.jks")
is only valid for your local machine.It will not working on CI/CD pipeline.
For that to work you have to give the relative path of your keystore file.