0
0
mirror of https://github.com/thunderbird/thunderbird-android.git synced 2024-09-20 04:02:14 +02:00

Add upload signing key support

This commit is contained in:
Wolf-Martell Montwé 2024-07-24 16:07:12 +02:00
parent 0cb1c7037a
commit 9255f7aa82
No known key found for this signature in database
GPG Key ID: 6D45B21512ACBF72
3 changed files with 41 additions and 11 deletions

View File

@ -106,7 +106,7 @@ android {
}
signingConfigs {
createSigningConfig(project, SigningType.K9_RELEASE)
createSigningConfig(project, SigningType.K9_RELEASE, isUpload = false)
}
buildTypes {

View File

@ -42,7 +42,7 @@ android {
applicationId = "net.thunderbird.android"
testApplicationId = "net.thunderbird.android.tests"
versionCode = 1
versionCode = 2
versionName = "0.1"
// Keep in sync with the resource string array "supported_languages"
@ -117,6 +117,8 @@ android {
versionNameSuffix = "-SNAPSHOT"
isMinifyEnabled = false
isShrinkResources = false
isDebuggable = true
}
release {
@ -124,6 +126,7 @@ android {
isMinifyEnabled = true
isShrinkResources = true
isDebuggable = false
proguardFiles(
getDefaultProguardFile("proguard-android.txt"),
@ -132,25 +135,39 @@ android {
}
create("beta") {
initWith(getByName("release"))
signingConfig = signingConfigs.getByType(SigningType.TB_BETA)
applicationIdSuffix = ".beta"
versionNameSuffix = "b1"
isMinifyEnabled = true
isShrinkResources = true
isDebuggable = false
matchingFallbacks += listOf("release")
proguardFiles(
getDefaultProguardFile("proguard-android.txt"),
"proguard-rules.pro",
)
}
create("daily") {
initWith(getByName("release"))
signingConfig = signingConfigs.getByType(SigningType.TB_DAILY)
applicationIdSuffix = ".daily"
versionNameSuffix = "a1"
isMinifyEnabled = true
isShrinkResources = true
isDebuggable = false
matchingFallbacks += listOf("release")
proguardFiles(
getDefaultProguardFile("proguard-android.txt"),
"proguard-rules.pro",
)
}
}

View File

@ -6,6 +6,7 @@ import org.gradle.api.Project
private const val SIGNING_FOLDER = ".signing"
private const val SIGNING_FILE_ENDING = ".signing.properties"
private const val UPLOAD_FILE_ENDING = ".upload.properties"
private const val PROPERTY_STORE_FILE = "storeFile"
private const val PROPERTY_STORE_PASSWORD = "storePassword"
@ -16,7 +17,7 @@ private const val PROPERTY_KEY_PASSWORD = "keyPassword"
* Creates an [ApkSigningConfig] for the given signing type.
*
* The signing properties are read from a file in the `.signing` folder in the project root directory.
* File names are expected to be in the format `$app.$type.signing.properties`.
* File names are expected to be in the format `$app.$type.signing.properties` or `$app.$type.upload.properties`.
*
* The file should contain the following properties:
* - `$app.$type.storeFile`
@ -26,9 +27,14 @@ private const val PROPERTY_KEY_PASSWORD = "keyPassword"
*
* @param project the project to create the signing config for
* @param signingType the signing type to create the signing config for
* @param isUpload whether the upload or signing config is used
*/
fun NamedDomainObjectContainer<out ApkSigningConfig>.createSigningConfig(project: Project, signingType: SigningType) {
val properties = project.readSigningProperties(signingType)
fun NamedDomainObjectContainer<out ApkSigningConfig>.createSigningConfig(
project: Project,
signingType: SigningType,
isUpload: Boolean = true,
) {
val properties = project.readSigningProperties(signingType, isUpload)
if (properties.hasSigningConfig(signingType)) {
create(signingType.type) {
@ -37,6 +43,8 @@ fun NamedDomainObjectContainer<out ApkSigningConfig>.createSigningConfig(project
keyAlias = properties.getSigningProperty(signingType, PROPERTY_KEY_ALIAS)
keyPassword = properties.getSigningProperty(signingType, PROPERTY_KEY_PASSWORD)
}
} else {
println("Signing config not created for ${signingType.type}")
}
}
@ -49,8 +57,13 @@ fun NamedDomainObjectContainer<out ApkSigningConfig>.getByType(signingType: Sign
return findByName(signingType.type)
}
private fun Project.readSigningProperties(signingType: SigningType) = Properties().apply {
val signingPropertiesFile = rootProject.file("$SIGNING_FOLDER/${signingType.id}$SIGNING_FILE_ENDING")
private fun Project.readSigningProperties(signingType: SigningType, isUpload: Boolean) = Properties().apply {
val signingPropertiesFile = if (isUpload) {
rootProject.file("$SIGNING_FOLDER/${signingType.id}$UPLOAD_FILE_ENDING")
} else {
rootProject.file("$SIGNING_FOLDER/${signingType.id}$SIGNING_FILE_ENDING")
}
if (signingPropertiesFile.exists()) {
FileInputStream(signingPropertiesFile).use { inputStream ->
load(inputStream)