Is it possible to take Res.readBytes("files/audio....
# compose-android
j
Is it possible to take Res.readBytes("files/audio.mp3") so can read it as raw or assets in Android when using compose components resources? Like Res.raw.audio it would be or Res.file.audio depending which format prefer. Using Compose 1.6.0 beta 2 release.
1
🧵 2
I do notice the plugin for fonts copy from composeResource/fonts to assets/fonts here: https://github.com/JetBrains/compose-multiplatform/blob/3040ea85bbc81cb6d1e22d6928[…]n/org/jetbrains/compose/resources/AndroidTargetConfiguration.kt Thats also explains oddness of having two folders in APK doing same things. Maybe a bug even, not sure?
Ok solved it myself:
Copy code
actual class PlatformResource(
    private val path: String
): MyResource {

    @Composable
    override fun absolutePath(): String {
        return LocalContext.current.packageResourcePath + "/" + path
    }

    @Composable
    fun asUri(): Uri {
        val absolutePath = absolutePath()
        val file = File(absolutePath)
        return Uri.parse("file:///android_asset/${file.name}")
    }
}
And then in my androidLibrary convention plugin adding:
Copy code
android {
        sourceSets["main"].apply {
          manifest.srcFile("src/androidMain/AndroidManifest.xml")
          assets.srcDir("src/commonMain/composeResources/files/assets")
        }
      }
Most probably helps someone else as well. Basically did same thing that Jetbrains doing for fonts, but also for treat everything as assets. Had to put subfolder into /files/assets as cannot have folder named assets inside composeResources directly 🙂 This is very ugly, as I need to have resource("files/assets/audio.mp3") being resolved different per platform. But it works for now.