Contrary to <this blog post> (which was very helpf...
# multiplatform
j
Contrary to this blog post (which was very helpful and insightful), I'm finding that src/commonTest/resources are not available to Android unit or instrumented tests. Is this expected behavior? Even adding
Copy code
kotlin {
  sourceSets {
    val androidTest by getting {
      resources.srcDir("src/commonTest/resources")
      ...
doesn't copy the resources from the common location for Android tests. Is there a good way to avoid duplicating these resource folders between source sets (hopefully other than a manual symlink)?
w
🤔 here we have this config for the module:
Copy code
private fun TestOptions.configure() = apply {
        unitTests.isIncludeAndroidResources = true
    }
So maybe that is what does the trick? At least for the unit tests. We have shared unit tests, and we are able to see the shared moko resources.
r
Isn't this issue related to the IDE dependency resolution bug present in AS Chipmunk + Bumblebee and Intellij EAP? I also can't access any of the
expect
declarations or any other classes/objects I have in
commonTest
inside
androidTest
but can access them inside
desktopTest
and
iOSTest
I'm guessing it is probably the same case with the resources folder too. I remember being able to acess the resources perfectly fine before the bug came along
j
It might be a new bug, but I don't think it's the same as the IDE errors where androidTest can't see commonTest code because that doesn't affect compile time resolution, whereas the resources are not present in the tests at runtime. I'm also seeing this with AS Dolphin, which does resolve the IDE errors for me.
@wbertan I'm assuming that's the same as
Copy code
android {
  testOptions.unitTests.isIncludeAndroidResources = true
  ...
I still don't get the src/commonTest/resources in Android tests with this option enabled.
With or without this option enabled, I do get the assets from src/androidAndroidTest/resources in my instrumented tests (this is where I really need them, not really unit tests). The resources are needed for common tests though, in both iOS and Android. This task works to copy them for iOS tests:
Copy code
val copyIosX64TestResources = tasks.register<Copy>("copyIosX64TestResources") {
    from("src/commonTest/resources")
    into("build/bin/iosX64/debugTest/resources")
}

tasks.findByName("iosX64Test")!!.dependsOn(copyIosX64TestResources)
I would think the
testOptions.unitTests.isIncludeAndroidResources = true
option was in order to include the resources from the application src/androidMain/resources location, and similarly would expect src/commonMain/resources to be included too. Is this how you're using it in your app?