1

In Compose Multiplatform, can I specify the order in which localized strings.xml files (e.g., values-ar, values-de, etc.) are processed, so that it can be deterministic.

Right now i have a build that is non-deterministic, leading to the generation of inconsistent resource classes, such as String0_commonMainKt and String1_commonMainKt? This unpredictability stems from the inherent filesystem or plugin processing order and not something that's easily controlled.

Compose Multiplatform expects resources organized under composeResources, with subdirectories like:

composeResources/
  └── values/             — default language
  └── values-fr/          — French
  └── values-de/          — German
  └── values-es/          — Spanish
  └── ...


compose.resources {
    publicResClass = true
    packageOfResClass = "com.module.project.resources"
    generateResClass = always
}

Qualifiers like language, theme, and density are supported and prioritized when collecting resources JetBrains.

The documentation does not provide a mechanism to enforce a custom ordering when multiple resource variants are processed.

So is there a way to actually order this to ensure deterministic builds?

Update: graldle.properties file:

#Gradle
org.gradle.jvmargs=-Xmx4048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx4048M" -XX:+UseSerialGC -Dkotlin.compiler.preciseCompilationResultsBackup=true

#Kotlin
kotlin.code.style=official

#Android
android.useAndroidX=true
android.nonTransitiveRClass=true

#MPP
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2

org.jetbrains.compose.experimental.uikit.enabled=true
kotlin.native.cacheKind=none

android.ndkVersion=27.0.12077973

# 16KB Page Size Support, NDK r27: Enable flexible page size support for Android 15+ devices
android.native.buildOutput=verbose
android.native.useNativeCompilerSettingsCache=false

# FOR REPRODUCIBLE BUILDS
kotlin.native.binary.reproducible=true
kotlin.native.distribution.downloadFromMaven=true

# Compose compiler consistency
androidx.compose.compiler.reportsDestination=build/compose_reports
androidx.compose.compiler.metricsDestination=build/compose_metrics

# Source timestamp for reproducible builds
SOURCE_DATE_EPOCH=1640995200

# Force deterministic builds
kotlin.collections.hash.seed=0
kotlin.mpp.stability.nowarn=true
kotlin.compiler.execution.strategy=in-process
kotlin.daemon.useFallbackStrategy=false
kotlin.incremental=false
org.gradle.parallel=false
kotlin.incremental.multiplatform=false

1 Answer 1

1

You can achieve this by adding a custom Gradle task to order the resources, add this to your build.gradle.kts file:

tasks.withType<org.jetbrains.compose.resources.GenerateResClassTask> {
    doFirst {
        // Force consistent ordering by sorting resource directories
        val resourceDirs = project.file("src/commonMain/composeResources")
            .listFiles { file -> file.isDirectory && file.name.startsWith("values") }
            ?.sortedBy { it.name }
        
        // Set system property to ensure consistent processing
        System.setProperty("compose.resources.processing.order", 
            resourceDirs?.joinToString(",") { it.name } ?: "")
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer, but then this also seems to be causing Unexpected diff output: Only in /tmp/tmp_6wu7beg/tmp_binaries_com.module.project.android_21.binary/content/assets/composeResources/com.module.project.resources: strings.xml When I tried running it on a CI. I think it solved the problem, but then created other problems.
@truthsayer Can you try adding org.gradle.parallel=false in your gradle.properties
That configuration is there, and I get the same issue. I have updated my question with my complete gradle.properties configurations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.