ios - 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。该插件似乎无法构建。这是我的设置的详细信息:
- Xcode v11.5
- IntelliJ IDEA v2020.1.2
- Cocoapods v1.9.1
- 摇篮 6.0.1
- 示例 repo ( https://github.com/touchlab/kotlin-native ) 注意:在 repo 中,我使用的是 ./samples/cocoapods
- 修改 ./samples/cocoapods/kotlin-library/build.gradle.kts 注释掉 AFNetworking,删除 AFNetworking pod
pod("AFNetworking", "~> 3.2.0")
添加新的 podpod("libPhoneNumber-iOS")
- 修改 ./samples/cocoapods/kotlin-library/gradle.properties 将此行更改
kotlin.native.home=../../../dist
为:#kotlin.native.home=../../../dist
- 在此文件夹的终端中:./
./gradlew podspec
samples/cocoapods/kotlin-library/ 这将在 ./samples/cocoapods/kotlin-library/build/cocoapods/defs/ 中创建一个 podspec 文件 (libPhoneNumber-iOS.def) - cd 从 kotlin-library 到 ios-app 文件夹
cd ../ios-app/
- 使用以下命令安装 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,例如:
- libPhoneNumberSwift
- LTPhoneNumberField 两者都无法使用 Kotlin 的 cocoapods 插件构建,但是在没有 Kotlin 的 cocoapod 插件的情况下作为 Pod 工作。
我错过了什么?
解决方案
这个特殊问题似乎是由 pod 名称中的破折号引起的。GitHub 上已经报告了一个问题。目前,建议通过重命名模块来解决此问题。改变你的kotlin-library/build.gradle.kts
喜欢
pod("libPhoneNumber-iOS", moduleName = "libPhoneNumber_iOS")
应该有帮助。请试一试,并在此处或在 GH 上告诉它是否有效。
推荐阅读
- r - 将pdf文件中的数据导入R
- reactjs - 我找不到在指定主机上运行的 docker 容器
- mysql - 如何处理 MySQL 节点查询?
- vue.js - 如何为 vuetify v-select 添加新选项
- java - 为什么 BigQuery 写入在 GCP Dataflow 中花费了这么多时间?
- angular - 为什么在 Angular 10 中安装 ng-bootstrap 后立即出现构建错误?
- rust - 如何展平两个结果
- javascript - 使用ajax登录时出现问题
- javascript - 仅当某些值为 true 时才运行 useEffect,但除非依赖关系发生变化,否则不要重新运行
- python - 将由不同形状的 numpy 数组组成的 numpy 数组保存到 .txt 文件