首页 > 解决方案 > Kotlin Native 项目中 iOS 上的 libPhonenumber(来自 Google)

问题描述

我一直在努力解决一个问题。

我正在使用 Kotlin Multiplatform (KMP) 构建一个跨平台应用程序(iOS 和 Android),我需要一个来自 Google 的库(https://github.com/google/libphonenumber)。

对于 Android,我可以指向一个 Maven 存储库(https://repo1.maven.org/maven2/com/googlecode/libphonenumber/libphonenumber/8.12.6/)。

对于 iOS,我可以通过 Cocoapods 使用 libPhonenumber 的 ObjC 端口。(https://cocoapods.org/pods/libPhoneNumber-ios)。

但是,我无法使用 Kotlin 的(cocoapod 插件)正确识别 Pod。该插件似乎无法构建。这是我的设置的详细信息:

  1. Xcode v11.5
  2. IntelliJ IDEA v2020.1.2
  3. Cocoapods v1.9.1
  4. 摇篮 6.0.1
  5. 示例 repo ( https://github.com/touchlab/kotlin-native ) 注意:在 repo 中,我使用的是 ./samples/cocoapods
  6. 修改 ./samples/cocoapods/kotlin-library/build.gradle.kts 注释掉 AFNetworking,删除 AFNetworking pod pod("AFNetworking", "~> 3.2.0") 添加新的 pod pod("libPhoneNumber-iOS")
  7. 修改 ./samples/cocoapods/kotlin-library/gradle.properties 将此行更改 kotlin.native.home=../../../dist 为: #kotlin.native.home=../../../dist
  8. 在此文件夹的终端中:./ ./gradlew podspec samples/cocoapods/kotlin-library/ 这将在 ./samples/cocoapods/kotlin-library/build/cocoapods/defs/ 中创建一个 podspec 文件 (libPhoneNumber-iOS.def)
  9. cd 从 kotlin-library 到 ios-app 文件夹 cd ../ios-app/
  10. 使用以下命令安装 Pod: pod install 您将看到如下内容:
Downloading dependencies
Installing kotlin_library (1.0)
Installing libPhoneNumber-iOS (0.9.15)
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 2 total pods installed.

当我在 Xcode 中构建示例“ios-app”目标:模拟器时,出现错误: fatal error: module 'libPhoneNumber' not found

我尝试过其他 libPhoneNumber pod,例如:

我错过了什么?

标签: iosxcodecocoapodskotlin-multiplatformkotlin-native

解决方案


这个特殊问题似乎是由 pod 名称中的破折号引起的。GitHub 上已经报告了一个问题。目前,建议通过重命名模块来解决此问题。改变你的kotlin-library/build.gradle.kts喜欢

 pod("libPhoneNumber-iOS", moduleName = "libPhoneNumber_iOS")  

应该有帮助。请试一试,并在此处或在 GH 上告诉它是否有效。


推荐阅读