0

I got library which includes some resource generating. I have the task for doing generating resources:

val updateWidgetResourcesProvider = tasks.register<Copy>("updateWidgetResources") {
    from("../../widget/")
    include("*.png")
    into("$sharedResLocation/raw")
    rename { "asset_$it".replace("@", "_").toLowerCase() }
}
android.libraryVariants.all {
    android.sourceSets[this.name].res.srcDirs(sharedResLocation)
    mergeResourcesProvider.configure {
        dependsOn(updateWidgetResourcesProvider)
    }
}

When I run :myLibrary:build everything works just perfect.

I also have an app, which uses library as dependency

dependencies {
    implementation(project(":myLibrary"))
}

Problem starts when I'm building :app:build. Task updateWidgetResourcesProvider simply not getting executed. How do I make a resource generating task so it both executed when I'm calling :app:build and :myLibrary:build. Also, why myLibrary's resource merger is not called when it is part of :app:build task?

I would appreciate any help, also, if I could read about android gradle task tree, and why it is different when I build AAR by itself or library as part of APK/Bundle.

Shchvova
  • 458
  • 5
  • 15

1 Answers1

0

After trying different things, I found a solution.

tasks.create<Copy>("updateWidgetResources") {
    val widgetResLocation = "$buildDir/generated/widgetResources"
    from("../../widget/")
    include("*.png")
    into("$widgetResLocation/raw")
    rename { "asset_$it".replace("@", "_").toLowerCase() }
    val task = this
    android.libraryVariants.all {
        registerGeneratedResFolders(files(widgetResLocation) {
            builtBy(task)
        })
    }
}

Shchvova
  • 458
  • 5
  • 15