You mean ContextAmbient.current?
On desktop there is no Context.
Why is it needed?
s
Spikey Sanju
11/09/2020, 1:41 PM
I'm using Moshi to read json from assets
Spikey Sanju
11/09/2020, 1:42 PM
Yes I mean ContextAmbient.current
i
Igor Demin
11/09/2020, 1:52 PM
Is the project multiplatform (android, desktop, common) or desktop-only?
If desktop-only then we can use something like this (to load file from "resources" folder):
Copy code
private fun loadResource(path: String): ByteArray {
val resource = Thread.currentThread().contextClassLoader.getResource(path)
requireNotNull(resource) { "Resource $path not found" }
return resource.readBytes()
}
If multiplatform - we can't load resources in "common" sourceSet.
But we can load them in android sourceSet with ContextAmbient.current.
And in desktop sourceSet with getResource