fix: separate oss/play build

This commit is contained in:
NickVs2015
2026-06-02 15:55:20 +03:00
parent 3a2b1c39bc
commit cf9e521fc1
5 changed files with 61 additions and 29 deletions
+41 -19
View File
@@ -78,9 +78,11 @@ android {
productFlavors {
create("oss") {
dimension = "billing"
buildConfigField("boolean", "IS_PLAY_BUILD", "false")
}
create("play") {
dimension = "billing"
buildConfigField("boolean", "IS_PLAY_BUILD", "true")
}
}
@@ -123,26 +125,46 @@ android {
output.outputFileName = "$outputBaseName-${buildType.name}.apk"
}
}
}
}
// Qt cmake expects APK at build/outputs/apk/{outputBaseName}-{buildType}-unsigned.apk
// (no flavor subdirectory). With product flavors Gradle puts the signed APK under
// build/outputs/apk/{flavor}/{buildType}/{outputBaseName}-{buildType}.apk.
// Copy to the path Qt cmake looks for so its zipalign/apksigner step can proceed.
val flavorName = productFlavors.firstOrNull()?.name ?: ""
if (flavorName.isNotEmpty()) {
val buildTypeName = buildType.name
// Qt cmake expects APK at build/outputs/apk/{outputBaseName}-{buildType}-unsigned.apk
// (no flavor subdirectory). With product flavors Gradle puts it under
// build/outputs/apk/{flavor}/{buildType}/. Copy to the flat path Qt cmake looks for.
packageApplicationProvider.configure {
doLast {
val srcDir = layout.buildDirectory.dir("outputs/apk/$flavorName/$buildTypeName").get().asFile
val dstDir = layout.buildDirectory.dir("outputs/apk").get().asFile
dstDir.mkdirs()
srcDir.listFiles()?.filter { it.name.endsWith(".apk") }?.forEach { apk ->
val dstName = apk.name.replace("${buildTypeName}.apk", "${buildTypeName}-unsigned.apk")
apk.copyTo(File(dstDir, dstName), overwrite = true)
}
// androiddeployqt expects:
// APK: build/outputs/apk/{base}-{buildType}[-unsigned].apk (no flavor subdir)
// AAB: build/outputs/bundle/{buildType}/{base}-{buildType}.aab (no flavor subdir)
// where {base} = outputBaseName (set by Qt Creator) or "android-build" (CI fallback).
// Release APK gets -unsigned suffix (Qt cmake signs it); debug does not.
applicationVariants.all {
val flavorName = productFlavors.firstOrNull()?.name ?: ""
val buildTypeName = buildType.name
// Copy play flavor only when invoked explicitly (android_play_apk/aab cmake targets pass -DexplicitRun=1).
// This prevents play from overwriting oss in the flat output dir during normal Qt Creator builds.
val isExplicitRun = project.findProperty("explicitRun") == "1"
val shouldCopy = flavorName == "oss" || (flavorName == "play" && isExplicitRun)
if (shouldCopy) {
val base = outputBaseName.ifEmpty { "android-build" }
val unsignedSuffix = if (buildTypeName == "release") "-unsigned" else ""
// APK: copy to outputs/apk/{base}-{buildType}[-unsigned].apk
packageApplicationProvider.configure {
doLast {
val srcDir = layout.buildDirectory.dir("outputs/apk/$flavorName/$buildTypeName").get().asFile
val dstDir = layout.buildDirectory.dir("outputs/apk").get().asFile
dstDir.mkdirs()
srcDir.listFiles()?.filter { it.name.endsWith(".apk") }?.forEach { apk ->
apk.copyTo(File(dstDir, "$base-$buildTypeName$unsignedSuffix.apk"), overwrite = true)
}
}
}
// AAB: copy to outputs/bundle/{buildType}/{base}-{buildType}.aab
tasks.named("bundle${name.replaceFirstChar { it.uppercase() }}") {
doLast {
val variantBundleDir = "${flavorName}${buildTypeName.replaceFirstChar { it.uppercase() }}"
val srcDir = layout.buildDirectory.dir("outputs/bundle/$variantBundleDir").get().asFile
val dstDir = layout.buildDirectory.dir("outputs/bundle/$buildTypeName").get().asFile
dstDir.mkdirs()
srcDir.listFiles()?.filter { it.name.endsWith(".aab") }?.forEach { aab ->
aab.copyTo(File(dstDir, "$base-$buildTypeName.aab"), overwrite = true)
}
}
}