From ab5963a04cb1e1d49a588b088fdb6530de62cf09 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 17 Dec 2023 18:56:04 +0800 Subject: [PATCH] Optimize artifacts copy task (#3842) We should avoid using internal APIs in AGP. Refs https://github.com/android/gradle-recipes/blob/1cd59c8951b59fd692f5194bfd451db2473975b9/addCustomAsset/build-logic/plugins/src/main/kotlin/CustomPlugin.kt#L63-L70. --- build.gradle | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index fc3ec582a4d..f286106e7de 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +import app.cash.licensee.LicenseeTask import com.android.build.gradle.api.AndroidBasePlugin import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -138,17 +139,22 @@ android { buildConfigField "int", "QUICKSTEP_MAX_SDK", quickstepMaxSdk } - applicationVariants.configureEach { variant -> - def capitalizedName = variant.name.capitalize() - def copyArtifactList = tasks.register("copy${capitalizedName}ArtifactList", Copy) { - dependsOn tasks.named("licenseeAndroid${capitalizedName}") - from reporting.file("licensee/android${capitalizedName}/artifacts.json") - into layout.buildDirectory.dir("generated/dependencyAssets/") - } - tasks.named("merge${variant.name.capitalize()}Assets").configure { - dependsOn copyArtifactList + androidComponents { + onVariants(selector().all()) { variant -> + def capName = variant.name.capitalize() + def licenseeTask = tasks.named("licenseeAndroid$capName", LicenseeTask) + def copyArtifactsTask = tasks.register("copy${capName}Artifacts", Copy) { + dependsOn(licenseeTask) + from(licenseeTask.map { it.outputDir.file("artifacts.json") }) + into(layout.buildDirectory.dir("generated/dependencyAssets")) + } + variant.sources.assets?.addGeneratedSourceDirectory(licenseeTask) { + objects.directoryProperty().fileProvider(copyArtifactsTask.map { it.destinationDir }) + } } + } + applicationVariants.configureEach { variant -> variant.outputs.configureEach { outputFileName = "Lawnchair ${variant.versionName}.apk" }