JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.03k stars 1.16k forks source link

Multi language string resources can't be decoded in 1.7.0 #5053

Closed Holetzky closed 2 months ago

Holetzky commented 3 months ago

Describe the bug I added values-de to my composeResources

composeApp/src/commonMain/composeResources/values/strings.xml composeApp/src/commonMain/composeResources/values-de/strings.xml

and load them with the stringResource method.

With version 1.6.11 all works fine.

With version 1.7.0-dev1703 the android app crashes when I change a value in values-de/strings.xml and change emulator language to German (-de).

Versions

To Reproduce Steps to reproduce the behavior:

  1. Create values-de/string.xml with app_name

`

Deutsch Appname

`

  1. Switch Emulator language to German accordingly
  2. Run this code snippet:
    @Composable
    fun BugReproduction() {
    Text(text = stringResource(Res.string.app_name))
    }
  3. Launch App to German Emulator, trying to read german string resource
  4. App crashes.

The stack trace looks like this:

java.lang.IllegalArgumentException: Invalid symbol ' '(12) at index 16 at kotlin.io.encoding.Base64.decodeImpl(Base64.kt:373) at kotlin.io.encoding.Base64.decode(Base64.kt:156) at kotlin.io.encoding.Base64.decode$default(Base64.kt:150) at kotlin.io.encoding.Base64.decode(Base64.kt:218) at kotlin.io.encoding.Base64.decode$default(Base64.kt:216) at org.jetbrains.compose.resources.StringResourcesUtilsKt.decodeAsString(StringResourcesUtils.kt:47) at org.jetbrains.compose.resources.StringResourcesUtilsKt.access$decodeAsString(StringResourcesUtils.kt:1) at org.jetbrains.compose.resources.StringResourcesUtilsKt$getStringItem$2.invokeSuspend(StringResourcesUtils.kt:41) at org.jetbrains.compose.resources.StringResourcesUtilsKt$getStringItem$2.invoke(Unknown Source:8) at org.jetbrains.compose.resources.StringResourcesUtilsKt$getStringItem$2.invoke(Unknown Source:2) at org.jetbrains.compose.resources.AsyncCache$getOrLoad$2$deferred$1$1.invokeSuspend(AsyncCache.kt:19) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277) at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69) at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1) at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:48) at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:1) at org.jetbrains.compose.resources.ResourceState_blockingKt.rememberResourceState(ResourceState.blocking.kt:15) at org.jetbrains.compose.resources.StringResourcesKt.stringResource(StringResources.kt:27) at

terrakok commented 3 months ago

I couldn't reproduce the problem. Could you share a reproducer project.

kotlin = "2.0.0"
compose = "1.7.0-dev1703"
image image
Holetzky commented 3 months ago

For some reason I am also no longer able to reproduce the problem today. Next time I will share a reproducer project. Thank you for the help.

kortchang commented 3 months ago

I faced a similar issue in compose-plugin = 1.7.0-alpha01, and I resolved it by doing a clean build.

Junzz0 commented 3 months ago

I faced a similar issue in compose-plugin = 1.7.0-alpha01, and I resolved it by doing a clean build.

kotlin = "2.0.0" compose = "1.7.0-alpha01" gradle = 8.8 AGP = 8.2.0

Ran into this issue as well.

It's normal to start editing the string, but then it will report an error, I thought it was caused by the values without the corresponding string, but the default string in the values still reported an error.

Junzz0 commented 3 months ago

clean and then re-run without reporting errors.

kortchang commented 3 months ago

I faced a similar issue in compose-plugin = 1.7.0-alpha01, and I resolved it by doing a clean build.

kotlin = "2.0.0" compose = "1.7.0-alpha01" gradle = 8.8 AGP = 8.2.0

Ran into this issue as well.

It's normal to start editing the string, but then it will report an error, I thought it was caused by the values without the corresponding string, but the default string in the values still reported an error.

I need to clean build every time I edit the strings.xml resources.

terrakok commented 3 months ago

Reproduced. The fix is in progress

terrakok commented 3 months ago

OK. I found the problem. It happens due my workaround the AGP issue with assets: https://issuetracker.google.com/348208777

if I remove this code:

if (androidComponents.pluginVersion >= agp_8_1_0) {
    // addGeneratedSourceDirectory doesn't mark the output directory as assets hence AS Compose Preview doesn't work
    tasks.configureEach { task ->
        if (task.name == kgpCopyAssetsTaskName) {
            task.outputs.files.forEach { file ->
                addStaticSourceDirectory(file.path)
            }
        }
    }
}

the problem will be fixed BUT AndroidStudio previews stop to work 😢

terrakok commented 3 months ago

The reason of the issue on the AGP side: https://issuetracker.google.com/issues/348208777#comment5

I reproduced it without the compose

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.