Is there a way I can configure `compose.resources`...
# multiplatform
a
Is there a way I can configure
compose.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
Copy code
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?
j
I doubt
compose.resources
belongs to
KotlinCompile
task. It allows to setup the output directory from another task
Copy code
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 directories
h
Hey Andrew, sorry to spoke at such an old thread, did you manage to solve this? I would like to use two different
customDirectory
, 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.
a
Hi Henrik, I'm not sure what I was working on when I posted that, but I'm sorry to say I don't know the answer. I moved on from that role and haven't touched KMP in the last 6 months. I hope you find a solution, hopefully KMP has something out-of-the-box now that would allow this.
h
Hey Andrew, thanks for responding! I did not find a proper fix for this but I did manage to find an acceptable workaround for it: We have out
design
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.
👍 1
Hopefully it might be helpful for someone else and good luck in the new role!