From 1108f2eb71c8148bf5841859209e99d583171355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 31 Mar 2021 10:51:59 +0200 Subject: [PATCH] [Gradle] Add configuration to store output files in release directory. --- app/build.gradle | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1e02f040..7d22ea41 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,15 +31,6 @@ android { } buildTypes { - applicationVariants.all { variant -> - variant.outputs.all { - if (variant.buildType.name == "release") { - outputFileName = "Edziennik_" + defaultConfig.versionName + ".apk" - } else { - outputFileName = "Edziennik_" + defaultConfig.versionName + "_debug.apk" - } - } - } debug { minifyEnabled = false } @@ -92,6 +83,30 @@ android { } } +tasks.whenTaskAdded { task -> + if (!task.name.endsWith("Release") && !task.name.endsWith("ReleaseWithR8")) + return + def renameTaskName = "rename${task.name.capitalize()}" + + def flavor = "" + if (task.name.startsWith("bundle")) + flavor = task.name.substring("bundle".length(), task.name.indexOf("Release")).uncapitalize() + if (task.name.startsWith("assemble")) + flavor = task.name.substring("assemble".length(), task.name.indexOf("Release")).uncapitalize() + if (task.name.startsWith("minify")) + flavor = task.name.substring("minify".length(), task.name.indexOf("Release")).uncapitalize() + + if (flavor != "") { + tasks.create(renameTaskName, Copy) { + from file("${projectDir}/${flavor}/release/"), file("${buildDir}/outputs/mapping/${flavor}Release/") + include "*.aab", "*.apk", "mapping.txt", "output-metadata.json" + destinationDir file("${projectDir}/release/") + rename ".+?\\.(.+)", "Edziennik_${android.defaultConfig.versionName}_${flavor}." + '$1' + } + task.finalizedBy(renameTaskName) + } +} + dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs')