5

我正在尝试在私有 CocoaPod 中添加使用 Kotlin/Native 构建的供应商框架,但出现错误:

  • 我已经用 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 导出框架的格式吗?

4

2 回答 2

8

您收到错误是因为默认情况下,Kotlin Native 只为单一架构生成二进制文件。CocoaPods 在尝试将其视为具有多种架构的“胖”二进制文件时会失败。因为无论如何你都需要多个架构(至少 arm64 用于设备,x86_64 用于模拟器),我使用的方法是创建这两个架构,然后将它们与lipo CocoaPods 出售所得的胖框架或只是拖动/drop 安装在 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"
}
于 2018-06-14T22:11:04.403 回答
2

Kotlin/Native 不会生成多架构(又名胖)二进制文件(请参阅https://en.wikipedia.org/wiki/Fat_binary),因此尝试lipo在它生成的框架上运行是没有意义的。

于 2018-02-28T09:53:08.693 回答