在Cocoapod中导入Kotlin / Native框架

让·西奥

我试图在私有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导出框架的格式?

戴维·贝里

您会收到此错误,因为默认情况下,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('@@[email protected]@', projectName)
            .replaceAll('@@[email protected]@', projectVersion)
    }
}

task export {
    dependsOn "exportFramework"
    dependsOn "exportPodspec"
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TOP 榜单

热门标签

归档