【问题标题】:Cannot add Google's "NearbyMessages" Cocoapod to Kotlin/Native project无法将 Google 的“NearbyMessages”Cocoapod 添加到 Kotlin/Native 项目
【发布时间】:2021-04-07 16:22:48
【问题描述】:

我想知道是否有人可以帮助我将 cocoapod 添加到 kotlin 本机模块中,到目前为止运气不佳!该库是 Google 的 NearbyMessages API。 https://developers.google.com/nearby/messages/ios/get-started

到目前为止我有:

  1. 使用 cocoapods 示例应用程序克隆了 KMM。 https://github.com/Kotlin/kotlin-with-cocoapods-sample。 (将 kotlin 插件版本号更改为 1.4.21,因为示例中引用的快照似乎不再可用)
  2. Gradle 同步并构建项目。一切顺利。
  3. 在 AFNetworking 行上方的 build.gradle.kts 中添加 NearbyMessages pod...pod("NearbyMessages")
  4. 现在,当我 gradle sync 时出现以下错误。
> Task :kotlin-library:cinteropNearbyMessagesIosArm64 FAILED
Exception in thread "main" java.lang.Error: /var/folders/t7/gwvnk41x66g5kmr7s7y8thdw0000gn/T/6648793494349780018.m:1:9: fatal error: module 'NearbyMessages' not found
    at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
    at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
    at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:507)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:265)
    at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
    at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
    at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
    at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
Execution failed for task ':kotlin-library:cinteropNearbyMessagesIosArm64'.
> Process 'command '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

我能够使用 podfile 和 pod install 来安装 cocoapod。不涉及 KMM。除此之外,我还尝试了各种随机的东西,但这些步骤看起来应该可行。

这是 NearbyMessages 的 podspec 文件: https://github.com/CocoaPods/Specs/blob/master/Specs/f/b/9/NearbyMessages/1.1.1/NearbyMessages.podspec.json

【问题讨论】:

标签: ios kotlin cocoapods kotlin-multiplatform kotlin-native


【解决方案1】:

JB 小伙伴们已经回复你了here

我在这里报告答案以获得更好的索引:

您好,Tom Pratt,感谢您的报告!据我所知, 问题是由NearbyMessages pod 包含一个静态的事实引起的 Objective-C 库,而不是框架。它没有module.modulemap,所以 cinterop 无法正确解释它。改变 build/cocoapods/defs/NearbyMessages.def 的内容有一个标题 选项而不是模块让我手动执行cinterop,但我不是 确保它可以在 Cocoapods 集成中完成。

他们建议作为手动解决方法:

另外,为了使这个手动解决方法更有用,您可以尝试 调整生成此 .def 文件的 Gradle 任务。只需添加

tasks.named<DefFileTask>("generateDefNearbyMessages").configure {
    doLast {
        outputFile.writeText("""
            language = Objective-C
            headers = GNSMessages.h
        """)
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    相关资源
    最近更新 更多