Reputation: 1217
I would like to know how I can include some resources in the shared code of a Kotlin Multiplatform project, so those resources are available when running the shared code in both platforms. I'd like to do this for resources both in the main and test targets. I'm not talking about resources of a Compose multiplatform app, each app would have its own native UI.
To give a better picture of what I'd like: I'm developing a mobile app with iOS and Android versions and I have the following:
apps
folder at root of my repodependencies/name-of-dep
folder at the root of the repo. The files I'm interested in are in a data
sub-folder (this is, dependencies/name-of-dep/data
from the root of the repo)apps/android
and apps/ios
for the native apps, and apps/core
for the KMP shared code, with the usual src/commonMain
, src/androidMain
and src/iosMain
sub-folders.root-of-repo
|- dependencies
| |- name-of-dep
| |- ... some other files
| |- data <- I'm interested in the files below this folder
|
|- apps
|- android <- Android app
|
|- core <- shared Kotlin code
| |- src
| |- androidMain
| |- commonMain
| | |- kotlin
| | |- resources <- does this work at all?
| |- commonTest
| | |- kotlin
| | |- resources <- does this work at all?
| |- iosMain
|
|- ios <- iOS app
I would like to:
dependencies/name-of-dep/data
to parse them and generate instances of the defined classes. This means being able to load the resources from both iOS and Android.core/src/commonTest
that check that I'm properly parsing the data filescore/src/commonTest
that may use additional test fixtures (below core/src/commonTest/resources
?)I've been reading and searching for a few hours, but there seems to be a lot of fragmented information (for example, talking about test resources but not release resources or viceversa), or seemingly contradicting information (should you use Compose resources even if you aren't using a Compose multiplatform approach?) so I'm really confused about what's the correct approach (maybe I may even manually copy the resources to a build folder??).
As a final remark, I'm well aware of expect
/actual
and how to load resources in each platform, my problem is to make the resources available in both platforms both for test and release targets.
Upvotes: 1
Views: 82