I’m trying to use HttpClient in a multi-platfrom p...
# kotlin-native
n
I’m trying to use HttpClient in a multi-platfrom project. When I run an iOS test via Gradle, I get this in the console:
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9807)
I understand that I need to add
NSAllowsArbitraryLoads
into the Info.plist. But how do I do it with Kotlin? There is no
Info.plist
.
s
n
So I have this Info.plist. But how do I affect the values in it? It’s regenerated each time, right?
s
Yes, it is auto generated. What you need to affect running iOS tests is to create a bundle with the test binary and your custom
Info.plist
.
n
Would you point me in the direction on how to approach this?
s
Sure. iOS application bundle is just a directory conforming to a particular layout. You can take a look to e.g. your final application bundle as an example. I guess you have Gradle task which runs iOS test binary on the simulator. This task should be modified: it should create the test application bundle directory, put proper
Info.plist
and test binary into it, and then use the binary from this bundle.
n
Okay, thank you, I get it. I’ll try it out.
For those who will find this thread in the future. This is a piece of Gradle script that helped me:
Copy code
task iosTest {
    def device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
    dependsOn 'linkTestDebugExecutableIos'
    group = JavaBasePlugin.VERIFICATION_GROUP
    description = "Runs tests for target 'ios' on an iOS simulator"

    doLast {
        def binary = kotlin.targets.ios.compilations.test.getBinary('EXECUTABLE', 'DEBUG')
        def infoPlistSrc = file("$rootProject.projectDir/src/iosTest/resources/Info.plist")
        def infoPlistDest = file("$binary.parentFile/Info.plist")

        Files.copy(infoPlistSrc.toPath(), infoPlistDest.toPath(), StandardCopyOption.REPLACE_EXISTING)

        exec {
            commandLine 'export', 'SIMCTL_CHILD_CFNETWORK_DIAGNOSTICS=3'
            commandLine 'xcrun', 'simctl', 'spawn', device, binary.absolutePath
        }
    }
}
s
Yes, something like this should work. Slack doesn’t keep history long enough, so I have reposted this solution to GitHub: https://github.com/JetBrains/kotlin-native/issues/2426 (I can refer you from this post if you tell me your GitHub name)