I upgraded to Xcode 11.4 today and running in the ...
# kotlin-native
s
I upgraded to Xcode 11.4 today and running in the iOS simulator works fine. However when trying to switch to a device it tells me that my framework was build for the simulator and gives me an error. Previously Xcode would just re-run the build script and the gradle build file would rebuild for the correct environment. Has anyone else run into this with the new Xcode?
My gradle build file swaps between targets using:
Copy code
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
        if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
            ::iosArm64
        else
            ::iosX64

    iOSTarget("ios") {
        binaries {
            framework {
                baseName = "Roll20Core"
                freeCompilerArgs = arrayListOf("-Xobjc-generics")
                embedBitcode("bitcode")
            }
        }
    }
The pack for xcode task is:
Copy code
val packForXcode by tasks.creating(Sync::class) {
    val targetDir = File(buildDir, "xcode-frameworks")

    /// selecting the right configuration for the iOS
    /// framework depending on the environment
    /// variables set by Xcode build
    val mode = (project.findProperty("XCODE_CONFIGURATION")?.toString()?.toUpperCase() ?: "DEBUG").split("_").first()
    val framework = kotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode)

    inputs.property("mode", mode)
    dependsOn(framework.linkTask)

    from({ framework.outputDirectory })
    into(targetDir)

    doLast {
        val gradlew = File(targetDir, "gradlew")
        gradlew.writeText(
            "#!/bin/bash\n"
                    + "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
                    + "cd '${rootProject.rootDir}'\n"
                    + "./gradlew \$@\n"
        )
        gradlew.setExecutable(true)
    }
}
m
Did you solve this? Just hit it myself in Xcode 4.11.1 in a project that used to work...
t
I have this as well but it works fine after a Gradle clean. So that is how I work around this issue at the moment.
m
Hmm, a Grade clean of my "shared" project followed by a build in Xcode results in
...Script-F7D1D3BA22B249CD00E4E352.sh: line 3: ./gradlew: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
. Was that the wrong Gradle clean?
t
No that is fine but I see your script could be a bit different than mine. In the example above I see that packForXcode is creating a gradlew file which I assume is called by Xcode. I have the code in that generated file directly in Xcode so it is not missing a file after a Gradle clean.
The only thing that the generated gradlew file does is a cd command and calling another gradlew file. Why not just put that directly in Xcode so it works after a Gradle clean, too?
m
Tried that and failed utterly 🙂 . My gradle skills are lacking. However telling Xcode to use the "Legacy build system" makes everything behave like it used to. In Xcode: File -> Project Settings... and then choose "Legacy Build System".
s
I haven’t solved it. I have a workaround that is good enough for now. I just delete the framework that kotlin generates before switching platforms.