Hi All, how can I read a file from resource direct...
# multiplatform
b
Hi All, how can I read a file from resource directory in shared -> commonMain
m
Try okio 3? It has apis to work with files
a
We are sharing string resources between ios and android and the way i do it is not so hard. I locate the json files under common folder and with a simple gradle script i copy those files under platform spesicif folders like assests in android. Then i created a ResourceReader class under common Module and write the platform spesific reader for both platforms and thats all
1
b
Do you mean have a script in shared gradle and then copy the files to platform specific folders and read on each platform separately?
m
Sorry I missed the
commonMain
part. okio will only help if the files are on the filesystem already (like during unit tests for an example). If you want to use them in iOS + Android @Ahmet Özcan is better. Also, you can take a look at https://github.com/icerockdev/moko-resources
b
Is there no way to read the file on KMM side?
m
Resources are not plain files. On the JVM they will be entries in a Jar file. On Android, they are packaged inside the APK. On iOS something else, etc...
If you want to read a file from the local filesystem, you can use Okio. If you want to use iOS/Android resources from
commonMain
, use moko-resources or what @Ahmet Özcan mentioned above with
expect/actual