Does anyone know how to get frameworks to be found...
# kotlin-native
m
Does anyone know how to get frameworks to be found when running unit tests. I have a module that depends on another module which is using cinterops to talk to an iOS framework. I was able to get the test app to build by adding this.
Copy code
kotlin {
    ios {
        val frameworkLocation = File(rootDir, "native/TestApp/Pods/Mapbox-iOS-SDK/dynamic/").absolutePath
        val frameworks = "-F$frameworkLocation"

        binaries.configureEach {
            linkerOpts(frameworks)
        }
    }
}
I get the following error when it runs the tests.
Copy code
dyld: Library not loaded: @rpath/Mapbox.framework/Mapbox
  Referenced from: /Users/mkrussel/pangea/pangea-android/test-app-shared/build/bin/iosX64/debugTest/test.kexe
  Reason: image not found
👀 2
a
to use frameworks in tests you should add environment variable:
Copy code
val frameworksPath =
                "${rootProject.buildDir.absolutePath}/cocoapods/UninstalledProducts/iphonesimulator"
            environment("SIMCTL_CHILD_DYLD_FRAMEWORK_PATH", frameworksPath)
try do it in doFirst for test task. and fix path to your
in our project configured test task with frameworks and network calls:
Copy code
// now standard test task use --standalone but it broke network calls
val newTestTask = tasks.create("iosX64TestWithNetwork") {
    val linkTask =
        tasks.getByName("linkDebugTestIosX64") as org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
    dependsOn(linkTask)

    group = JavaBasePlugin.VERIFICATION_GROUP
    description = "Runs tests for target 'ios' on an iOS simulator"

    doLast {
        val binary = linkTask.binary.outputFile
        val device = "iPhone 8"
        exec {
            commandLine = listOf("xcrun", "simctl", "boot", device)
            isIgnoreExitValue = true
        }
        exec {
            val frameworksPath =
                "${rootProject.buildDir.absolutePath}/cocoapods/UninstalledProducts/iphonesimulator"
            environment("SIMCTL_CHILD_DYLD_FRAMEWORK_PATH", frameworksPath)
            commandLine = listOf(
                "xcrun",
                "simctl",
                "spawn",
                device,
                binary.absolutePath
            )
        }
        exec {
            commandLine = listOf("xcrun", "simctl", "shutdown", device)
        }
    }
}
with(tasks.getByName("iosX64Test")) {
    dependsOn(newTestTask)
    onlyIf { false }
}
m
That worked thanks.
Final solution I came up with was.
Copy code
tasks.withType(KotlinNativeTest::class.java) {
    environment("SIMCTL_CHILD_DYLD_FRAMEWORK_PATH", frameworkLocation)
}
This doesn't open a visible simulator and generates the test results.
👍 1