I have a KMP library, string resources are defined...
# compose
t
I have a KMP library, string resources are defined in the commonMain/composeResources. The androidMain source set accesses the resources using the
Res
API of CMP. Sample app in the project works fine, but when I publish the library, and use it a different app, I get a crash because resources couldn't be found. Is this a known thing? If yes, how does the current libraries handle this? This is what I got during my research:
CMP resources work in published libraries. The issue is that the .cvr files need to be bundled in the AAR's assets/ directory
Stack trace:
Copy code
Error was captured in composition.
org.jetbrains.compose.resources.MissingResourceException: Missing resource with path: composeResources/com.daiatech.waveform/values/strings.commonMain.cvr
	at org.jetbrains.compose.resources.DefaultAndroidResourceReader.throwMissingResourceException(ResourceReader.android.kt:93)
	at org.jetbrains.compose.resources.DefaultAndroidResourceReader.getResourceAsStream(ResourceReader.android.kt:80)
	at org.jetbrains.compose.resources.DefaultAndroidResourceReader.readPart(ResourceReader.android.kt:32)
	at org.jetbrains.compose.resources.StringResourcesUtilsKt$getStringItem$2.invokeSuspend(StringResourcesUtils.kt:26)
	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(ResourceCaches.kt:23)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:263)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:94)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:70)
	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 com.daiatech.waveform.AudioPlayerKt.AudioPlayer(AudioPlayer.kt:124)
	at com.daiatech.waveform.AudioPlayerKt.AudioPlayer(AudioPlayer.kt:93)
	at com.daiatech.waveform.segmentation.AudioSegmentationUiKt.AudioSegmentationUi(AudioSegmentationUi.kt:214)
	at (SomeFileInMyApp.kt:196)
Ok. Looks like, the crash is still happening in local build and not just in published AAR. However, adding this flag, fixes this.
Copy code
experimentalProperties["android.experimental.kmp.enableAndroidResources"] = true