我正在尝试添加一个用Kotlin/Native在私有Cocoapod中构建的自动添加框架,但我得到一个错误:
我已经用Kotlin/Native生成了一个iOS框架。
我将框架文件夹(由Konan编译/生成)复制到我的自定义pod文件夹中。
在podspec中,我将框架路径添加到“vendored_frameworks”列表中。
我启动pod repo push myCocoapodsRepo myProject.podspec --verbose"
我收到一个错误:[iOS] xcodebuild: fatal error: lipo: input file (/Users/jeandaube/Library/Developer/Xcode/DerivedData/App-auugdpsmbbpvarfzghxatkvwftsn/Build/Products/Release-iphonesimulator/App.app/Frameworks/MyProject.framework/MyProject) must be a fat file when the -remove option is specified
我应该以某种方式更改如何首先使用Konan导出框架的格式吗?
最佳答案:
您得到错误是因为,默认情况下,KotlinNative只为单个体系结构生成二进制文件。cocoapods-than在尝试将其视为具有多个体系结构的“胖”二进制时失败。由于您无论如何都需要多个体系结构(设备至少需要arm64,模拟器至少需要x86_64),我使用的方法是创建两个体系结构,然后将它们与lipo
合并,最终的fat框架可以由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"
}