首页 > 解决方案 > 构建iOS框架时使用build.gradle.kts将文件添加到.framework

问题描述

我正在使用 Kotlin 多平台,我想知道在为 iOS 构建时是否可以将一些文件放入 .framwork。以下是我的 build.gradle.kts 文件的一部分:

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)
    }
}

构建后,我将在 build 文件夹下获得 xcode-frameworks。和xcode-frameworks下的xxx.framework。构建时如何将文件放入 xxx.framework?(ps.不是xcode-frameworks下的文件,而是xxx.framework下的一些文件)

标签: kotlinframeworksgradle-kotlin-dslkotlin-multiplatform

解决方案


推荐阅读