0

I am using Kotlin multiplatform, and I'd like to know is it possible to put some files to .framwork when build for iOS. Following is part of my build.gradle.kts file:

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 = System.getenv("CONFIGURATION") ?: "DEBUG"
    val framework = kotlin.targets
        .getByName<KotlinNativeTarget>("ios")
        .binaries.getFramework(mode)
    inputs.property("mode", mode)
    dependsOn(framework.linkTask)

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

    /// generate a helpful ./gradlew wrapper with embedded Java path
    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)
    }
}

After building, I will get the xcode-frameworks under build folder. And xxx.framework under xcode-frameworks. How can I put files into xxx.framework when building? (ps. not the file under xcode-frameworks, some files in xxx.framework instead)

James Fu
  • 444
  • 1
  • 8
  • 21
  • hello! I think one can do it by manual copying resources by the Gradle script, just as you do for `xcode-frameworks` directory. Also, It might be helpful to have a look at [this](https://github.com/icerockdev/moko-resources) library. – Artyom Degtyarev Oct 28 '19 at 09:05
  • So that I cannot write something in Gradle script to achieve my goal? The library you provided looks a little complicated. – James Fu Oct 28 '19 at 09:45
  • I just said that you can. Maybe something like [that](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy) can help? – Artyom Degtyarev Oct 28 '19 at 10:31
  • @JamesFu did you find a solution? I'm in the same situation, and I've managed to copy the files but then I can't use the framework due to (maybe signature?) errors – achojoao Nov 09 '20 at 09:07

0 Answers0