I want to make a signed apk file on the Android Gradle build, but I'm not sure if the code below is correct. What did I miss out on the gradle build?
android {
...
signingConfigs {
release {
storeFile file("release.keystore")
storePassword "******"
keyAlias "******"
keyPassword "******"
}
}
}
Gradle build works well. build/apkIf you look at the folders, there are only ...-release-unsigned.apk and ...-debug-unaligned.apk. I want to make a signed apk, what should I do?
android gradle apk release android-gradle
In the Gradle script, you can also use the System.console().readLine method to receive user input, as shown in the code below.
...
signingConfigs {
release {
storeFile file(System.console().readLine("\n\$ Enter keystore path: "))
storePassword new String(System.console().readPassword("\n\$ Enter keystore password: "))
keyAlias System.console().readLine("\n\$ Enter key alias: ")
keyPassword new String(System.console().readPassword("\n\$ Enter key password: "))
}
}
You are prompted to enter each parameter. But in this situation, it's better to set these parameters as environmental variables. Gradle allows you to access the environment variable with System.getenv("<variable name>")
...
signingConfigs {
release {
storeFile file(System.getenv("KEYSTORE"))
storePassword System.getenv("KEYSTORE_PASSWORD")
keyAlias System.getenv("KEY_ALIAS")
keyPassword System.getenv("KEY_PASSWORD")
}
}
© 2024 OneMinuteCode. All rights reserved.