Andrew Kelly
11/13/2024, 1:53 PMcompose.resources so that I can include drawables from different build flavors? This is a shared module, not an Android module. Currently I'm doing this
tasks.withType<KotlinCompile>().all {
compose.resources {
publicResClass = true
generateResClass = always
val flavorName = if (name.contains("Flavor1")) {
"flavor1"
} else {
"flavor2"
}
customDirectory(
sourceSetName = "commonMain",
directoryProvider = provider { layout.projectDirectory.dir("src/$flavorName/resources") }
)
}
}
And this seems to find the correct file, but it completely replaces the commonMain/composeResources folder, its no longer used. Is there a way to have the commonMain/composeResources and my build flavor directory used for the creation of drawables?Javier
11/13/2024, 2:34 PMcompose.resources belongs to KotlinCompile task.
It allows to setup the output directory from another task
directoryProvider = tasks.register<DownloadRemoteFiles>
{...}
abstract class DownloadRemoteFiles : DefaultTask() {
@get:OutputDirectory
val outputDir = layout.buildDirectory.dir("downloadedRemoteFiles")
@TaskAction
fun run() { /* your code for downloading files */ }
}
compose.resources {
customDirectory(
sourceSetName = "iosMain",
directoryProvider = tasks.register<DownloadRemoteFiles>("downloadedRemoteFiles").map { it.outputDir.get() }
)
}
But it has no mentions about supporting multiple directoriesHenrik G
10/04/2025, 3:52 AMcustomDirectory, both adding to commonMain, but I find that the second customDirectory replaces the first one. If there is a way to add these together that’d be fantastic.Andrew Kelly
11/07/2025, 1:13 AMHenrik G
11/07/2025, 1:19 AMdesign module with most of the resources, in the main design module I had pointed the composeResource to the android res directory, this enabled us to use both Android R in the legacy part of the Android codebase but still get a Compose resource Res without duplicating the resources. This worked great for drawables, but when it came to raw resources, the systems did not play nice with each other where android’s raw only accepts .xml files, not .json (for lottie files), but I could not put it in files/ either (I think Android pipeline didn’t like that folder), I don’t remember exactly now.
In the end, for the raw resources, I created a temporary design-files module that the design modules adds via api, so design-files is using composeResources and exposes those under a different Res files, in our case we only have a few raw files so it was an acceptable compromise vs hundreds of drawables.Henrik G
11/07/2025, 1:20 AM