我试图在私人CocoaPod中添加使用Kotlin / Native构建的销售框架但是我收到错误:
{{1}}
我是否应该以某种方式改变我首先使用Konan导出框架的格式?
答案 0 :(得分:8)
您正在收到错误,因为默认情况下,Kotlin Native仅为单个体系结构生成二进制文件。当CocoaPods试图将它作为一种"脂肪"具有多种架构的二进制文件既然你无论如何都需要多个架构(至少arm64用于设备而x86_64用于模拟器),我使用的方法是创建两个架构,然后将它们与lipo
合并。结果胖框架然后可以通过CocoaPods销售,或者只是在Xcode中安装拖放。
def outputDirectory = "$export_dir/$projectName/$projectVersion"
def outputFramework = "$outputDirectory/${projectName}.framework"
konanArtifacts {
// Declare building into a framework, build arm64 for device, x64 for simulator
framework(projectName, targets: ['ios_arm64', 'ios_x64' ]) {
// The multiplatform support is disabled by default.
enableMultiplatform true
}
}
// combine original arm64 and x64 libraries into a single library in
// the exported framework folder
task combineArchitectures(type: Exec, dependsOn: compileKonanLibrary) {
executable 'lipo'
args = [
'-create',
'-arch',
'arm64',
new File(compileKonanLibraryIos_arm64.artifact, 'Library'),
'-arch',
'x86_64',
new File(compileKonanLibraryIos_x64.artifact, 'Library'),
'-output',
"$outputFramework/Library"
]
}
// export the arm64 (doesn't matter which really) framework, skipping
// the library binary itself
task exportFramework(type: Copy, dependsOn: compileKonanLibrary) {
from compileKonanLibraryIos_arm64.artifact
into outputFramework
exclude projectName
finalizedBy combineArchitectures
}
// build a pod spec by copying and updating a template file
task exportPodspec(type: Copy) {
from "Library.podspec"
into outputDirectory
filter {
it.replaceAll('@@projectName@@', projectName)
.replaceAll('@@projectVersion@@', projectVersion)
}
}
task export {
dependsOn "exportFramework"
dependsOn "exportPodspec"
}
答案 1 :(得分:2)
Kotlin / Native不会产生多体系结构(又称胖)二进制文件(参见https://en.wikipedia.org/wiki/Fat_binary),因此尝试在它生成的框架上运行lipo
是没有意义的。