build(Needs bump): Sign APK properly without relying on internal Gradle classes

This commit is contained in:
oSumAtrIX 2024-07-15 00:37:37 +02:00
parent 2fabdb245f
commit 7af763f4b1
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4

View File

@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.android.application) alias(libs.plugins.android.application)
alias(libs.plugins.kotlin) alias(libs.plugins.kotlin)
publishing publishing
signing
} }
android { android {
@ -53,28 +54,27 @@ dependencies {
compileOnly(project(":stub")) compileOnly(project(":stub"))
} }
tasks {
// Because the signing plugin doesn't support signing APKs, do it manually.
register("sign") {
group = "signing"
dependsOn(build) tasks {
val assembleReleaseSignApk by registering {
dependsOn("assembleRelease")
val apk = layout.buildDirectory.file("outputs/apk/release/${rootProject.name}-$version.apk")
inputs.file(apk).withPropertyName("input")
outputs.file(apk.map { it.asFile.resolveSibling("${it.asFile.name}.asc") })
doLast { doLast {
val outputDirectory = layout.buildDirectory.dir("outputs/apk/release").get().asFile signing {
val integrationsApk = outputDirectory.resolve("${rootProject.name}-$version.apk") useGpgCmd()
sign(*inputs.files.files.toTypedArray())
org.gradle.security.internal.gnupg.GnupgSignatoryFactory().createSignatory(project).sign( }
integrationsApk.inputStream(),
outputDirectory.resolve("${integrationsApk.name}.asc").outputStream(),
)
} }
} }
// Needed by gradle-semantic-release-plugin. // Needed by gradle-semantic-release-plugin.
// Tracking: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435 // Tracking: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435.
publish { publish {
dependsOn(build) dependsOn(assembleReleaseSignApk)
dependsOn("sign")
} }
} }