我目前正在从事 Kotlin Multiplatform 项目。我们正在使用 Moko 资源 ( https://github.com/icerockdev/moko-resources ) 创建资源的共享目录。这适用于 FAT 框架,但是我们需要使用 XCFrameworks。我对iOS和框架情况不是很熟悉,所以请原谅我的无知。
现在,当我们构建 XCFramework 时似乎出了点问题,因为运行该应用程序显示 commainMain.MR 不可用,所以我认为我们的包没有被正确复制。
这是我们的fatFramework Gradle 任务:
register("buildFatFrameworkWithResources", TestFatFramework::class) {
val debugMode = "DEBUG"
val mode = System.getenv("CONFIGURATION") ?: debugMode
destinationDir = buildDir.resolve("xcode-universal-framework")
group = "Universal framework"
description = "Builds a universal (fat) $mode framework"
from(iosArm64Framework, iosX64Framework)
dependsOn(iosArm64Framework.linkTask)
dependsOn(iosX64Framework.linkTask)
}
还有我们的XCFramework任务
register("buildXcFrameworkWithResources") {
dependsOn("deleteXcFramework")
val mode = "DEBUG"
val frameworks = arrayOf("iosArm64", "iosX64").map {
kotlin.targets.getByName<KotlinNativeTarget>(it).binaries.getFramework(mode)
}
inputs.property("mode", mode)
dependsOn(frameworks.map { it.linkTask })
group = "Universal framework"
description = "Builds a universal (xc) $mode framework"
frameworks.first().outputFile.listFiles()
?.asSequence()
?.filter { it.name.contains(".bundle") }
?.forEach { bundleFile ->
project.copy {
from(bundleFile)
into("$xcFrameworkPath/${bundleFile.name}")
}
}
doLast {
val buildArgs: () -> List<String> = {
val arguments = mutableListOf("-create-xcframework")
frameworks.forEach {
arguments += "-framework"
arguments += "${it.outputDirectory}/${project.name}.framework"
}
arguments += "-output"
arguments += xcFrameworkPath
arguments
}
exec {
executable = "xcodebuild"
args = buildArgs()
}
}
}
我不太确定需要更改哪些内容才能使其正常工作。感谢任何帮助!