kotlin - 无法在 iOS 中构建 KMM 应用程序的发布版本
问题描述
我正在尝试在 iOS 上为我的 KMM 应用程序构建发布版本。进度失败并显示消息
Exception in thread "main" java.lang.IllegalStateException: Could not find 'libCryptoKitWrapper.a' binary in neither of [CryptoKitWrapper/build/Release-iphoneos]
异常跟踪到我正在使用的 Swift 库。为了让它在 kotlin 上工作,我正在使用这种方法。令人惊讶的是,有问题的文件可以在列出的目录中找到。这里可能有什么问题?相关 cinterop 任务:
iosTarget("ios") {
val platform = when (preset?.name) {
"iosX64" -> "iphonesimulator"
"iosArm64" -> "iphoneos"
else -> error("Unsupported target $name")
}
compilations.getByName("main") {
cinterops.create("CryptoKitWrapper") {
val interopTask = tasks[interopProcessingTaskName]
interopTask.dependsOn(":CryptoKitWrapper:build${platform.capitalize()}")
includeDirs.headerFilterOnly("$rootDir/CryptoKitWrapper/build/Release-$platform/include")
}
}
}
解决方案
问题是由于 Gradle 将设置的位置解释libraryPaths
为相对路径,从当前操作系统目录派生。要观察这一点,请尝试./gradlew :shared:cinteropCryptoKitWrapperIos --info
从SwiftLibSample
dir 和../gradlew cinteropCryptoKitWrapperIos --info
from执行SwiftLibSample/shared
。第一个应该可以正常工作。
要解决此问题,可以执行以下操作。不要硬编码文件的路径,而是在块.def
内设置此参数。cinterops{...}
我尝试了这个,灵感来自 @SalomonBRYS 在https://github.com/JetBrains/kotlin-native/issues/2314的回答
cinterops.create("CryptoKitWrapper") {
...
extraOpts("-libraryPath", "$rootDir/CryptoKitWrapper/build/Release-$platform")
...
如果您想收到有关此问题的更新,请在官方 Kotlin 问题跟踪器KT-48082上关注此问题
编辑:以下内容与原始问题没有直接关系,我只想从下面的评论部分总结我的提示。
要启用项目布局中使用的位码,如https://github.com/MJegorovas/SwiftLibSample中所示,应该:
使静态库包含 Bitcode。在这种情况下,
"BITCODE_GENERATION_MODE=bitcode"
选项应该跨xcodebuild
参数。使 cinterop 工具将库与位码链接。将
-lto-embed-bitcode
链接器选项添加到.def
文件。
推荐阅读
- spring - 如何在 Spring MVC(不是 Spring Boot)应用程序中自定义 Jackson
- c# - 将正确的 JSON 作为参数发送到 RPC
- java - Kafka 流 - 基于动态条件数量的连接谓词
- c# - 我需要让 Active Directory 登录在 C# whit net core 3.1 上工作
- python - 具有多行值的 PEP8 多行字典
- r - R:根据Y列中的ID组合X列的多行内容
- google-cloud-platform - GCP 从现有虚拟机创建实例模板
- java - 如何确定活动在哪个日历上?
- python - Python 数据表:sum、groupby、column < 0
- html - 如何为列中的图像设置中心对齐并使文本出现在其下方?