The mechanism in Jetbrains components resources. It looks like they use some kind of ResourceLoader ...
j
The mechanism in Jetbrains components resources. It looks like they use some kind of ResourceLoader between iOS and Android. For iOS using NsBundle, like: NSBundle.mainBundle.resourcePath But for Android it feels like they using reflections through Java resources instead. But I dont follow, if I want to have same path they using, same parent folder to inject into same resource sharing but my own way, how do I do that? Like if I put a video file in shared module, that will be copied into iOS bundle and for Android/JVM it will be resources folder I think. Just not entirely sure how to fetch it the same way on all platforms 😄 Maybe there is some raw reference I can use, to ONLY get the path? In my case I need NSUrl on iOS and on Android Uri because framework I use require so. On iOS I think its:
Copy code
NSURL.fileURLWithPath(NSBundle.mainBundle.resourcePath + "/compose-resources/" + path)
Where path is relative path from the shared resources folder. Source code for Android is:
Copy code
@ExperimentalResourceApi
actual fun resource(path: String): Resource = AndroidResourceImpl(path)

@ExperimentalResourceApi
private class AndroidResourceImpl(path: String) : AbstractResourceImpl(path) {
    override suspend fun readBytes(): ByteArray {
        val classLoader = Thread.currentThread().contextClassLoader ?: (::AndroidResourceImpl.javaClass.classLoader)
        val resource = classLoader.getResourceAsStream(path)
        if (resource != null) {
            return resource.readBytes()
        } else {
            throw MissingResourceException(path)
        }
    }
}
But I want to get the path and not the bytes 😄
m
There is no filesystem path to a resource on Android. It is not a file on the filesystem. There is the ill-used
android.resource
scheme you can use for a
Uri
, and it is just based off of the resource identifier.
j
There is path relative to the apk root. So Yeah can use it. Solved it by copy video in shared resources as raw type into Android resources from jetbrains resources. Regular path seemed non accessible for media it seems. And then used getResourceIdentifier + android.resources. thanks!