Skip to content

Commit

Permalink
[gradle] Fix AGP task dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrakok committed Jul 18, 2024
1 parent 5d22f7c commit 283cb84
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ internal fun Project.configureAndroidComposeResources(
//copy all compose resources to android assets
val androidComponents = project.extensions.findByType(AndroidComponentsExtension::class.java) ?: return
androidComponents.onVariants { variant ->
val camelVariantName = variant.name.uppercaseFirstChar()
val variantAssets = getVariantComposeResources(variant)
val variantAssetsDir = layout.buildDirectory.dir(RES_GEN_DIR).dir(variant.name + "AndroidAssets")

val copyVariantAssets = tasks.register(
"copy${variant.name.uppercaseFirstChar()}ComposeResourcesToAndroidAssets",
"copy${camelVariantName}ComposeResourcesToAndroidAssets",
Copy::class.java
) { task ->
task.from(variantAssets)
Expand All @@ -56,12 +57,16 @@ internal fun Project.configureAndroidComposeResources(
val staticDir = variantAssetsDir.get().asFile
staticDir.mkdirs()
variant.sources.assets?.addStaticSourceDirectory(staticDir.path)

val agpTaskNames = listOf(
//fix agp task dependencies for build and allTests tasks
"merge${camelVariantName}Assets",
"package${camelVariantName}Assets",
//fix agp task dependencies for AndroidStudio preview
"compile${camelVariantName}Sources",
)
tasks.configureEach { task ->
if (task.name == "merge${variant.name.uppercaseFirstChar()}Assets") {
task.dependsOn(copyVariantAssets)
}
//fix task dependencies for AndroidStudio preview
if (task.name == "compile${variant.name.uppercaseFirstChar()}Sources") {
if (task.name in agpTaskNames) {
task.dependsOn(copyVariantAssets)
}
//fix linter task dependencies for `build` task
Expand Down

0 comments on commit 283cb84

Please sign in to comment.