libres icon indicating copy to clipboard operation
libres copied to clipboard

Able to work with multiple source dir

Open jershell opened this issue 2 years ago • 6 comments

Current state of kotlin multiplatform not support "flavors\builttypes". But its not trouble. Just enough do more sources by conditions

        val commonMain by getting {
            if(BUILD_TYPE == BUILD_TYPE.STAGE) {
                val variantSrc = "${project.rootDir}/app/src/variantMainStage/kotlin"
                val variantResources = "${project.rootDir}/app/src/variantMainStage/libres"
                kotlin.srcDir(variantSrc)
                resources.srcDir(variantResources)
            } else {
                // default
                val variantSrc = "${project.rootDir}/app/src/variantMainDemo/kotlin"
                val variantResources = "${project.rootDir}/app/src/variantMainDemo/libres"
                kotlin.srcDir(variantSrc)
                resources.srcDir(variantResources)
            }
...
}

Its work. We have same set of dependencies that containt commonMain and look like a habitual androids flavor setup

But libres dont see an alternative resources. Do you khow how to fix it?

jershell avatar Jun 16 '23 09:06 jershell

Done. About pr. The plugin takes into account all sources of initial resources and merges their values. in the case of image files, the file will be added to the share or replaced when the filenames match. Strings. If the string line exists, it will be replaced, if not, it will be added. The first source is commonMain.

jershell avatar Jun 19 '23 07:06 jershell

Sorry for long reply. I looked at your PR. Looks good, but I have another idea with a more customizable API. It will require a little more code in the project's build.gradle, but at the same time it will avoid "crutches" inside the library for such implementation of flavors (and less changes in the library).

It might look like this

tasks.withType(LibresStringGenerationTask::class) {
    inputDirectory.add(file("src/variantDemoMain/libres/strings"))
}

What do you think?

Skeptick avatar Jun 22 '23 22:06 Skeptick

I'm not sure, it's like overwriting a resource file when only the lines inside the file need to be overridden like in pr.

jershell avatar Jun 23 '23 07:06 jershell

The logic is the same as in your PR, only without automatic finding but with ability to flexibly add files and directories with resources, wherever they are located

Skeptick avatar Jun 24 '23 10:06 Skeptick

My PR does merge xml to single resource file and override lines inside. Your proposal will rewrite a file. Not lines. mutableAccumulator.getOrPut(lang, ::mutableMapOf).putAll(list.associateBy { it.name })

jershell avatar Jun 24 '23 16:06 jershell

I think its difference cases. We can add a flag to settings like a separateResources = true / false. It could resolve the inconsistency

jershell avatar Jun 24 '23 20:06 jershell