Thread
#multiplatform
    b

    Brian Donovan

    10 months ago
    Hi All, how can I read a file from resource directory in shared -> commonMain
    mbonnin

    mbonnin

    10 months ago
    Try okio 3? It has apis to work with files
    Ahmet Özcan

    Ahmet Özcan

    10 months ago
    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
    b

    Brian Donovan

    10 months ago
    Do you mean have a script in shared gradle and then copy the files to platform specific folders and read on each platform separately?
    mbonnin

    mbonnin

    10 months ago
    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

    Brian Donovan

    10 months ago
    Is there no way to read the file on KMM side?
    mbonnin

    mbonnin

    10 months ago
    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