Search code examples
iosxcodecocoapodskotlin-multiplatformkotlin-native

libPhonenumber (from Google) on iOS in a Kotlin Native project


I've been struggling to solve a problem.

I'm building a cross platform app (iOS and Android) using Kotlin Multiplatform (KMP) where I need a library from Google (https://github.com/google/libphonenumber).

For Android, I can point to a Maven repo (https://repo1.maven.org/maven2/com/googlecode/libphonenumber/libphonenumber/8.12.6/).

For iOS, I can use a ObjC port of libPhonenumber via Cocoapods.(https://cocoapods.org/pods/libPhoneNumber-ios).

But, I can't use Kotlin's (cocoapod plugin) to properly recognize the Pod. The plugin appears to fail to build. Here's the details of my setup:

  1. Xcode v11.5
  2. IntelliJ IDEA v2020.1.2
  3. Cocoapods v1.9.1
  4. Gradle 6.0.1
  5. Sample repo (https://github.com/touchlab/kotlin-native) NOTE: Within the repo, I'm using ./samples/cocoapods
  6. modify ./samples/cocoapods/kotlin-library/build.gradle.kts commented out AFNetworking, remove AFNetworking pod pod("AFNetworking", "~> 3.2.0") add a new pod pod("libPhoneNumber-iOS")
  7. modify ./samples/cocoapods/kotlin-library/gradle.properties change this line: kotlin.native.home=../../../dist to this: #kotlin.native.home=../../../dist
  8. in Terminal in this folder: ./samples/cocoapods/kotlin-library/ ./gradlew podspec This creates a podspec file (libPhoneNumber-iOS.def) in ./samples/cocoapods/kotlin-library/build/cocoapods/defs/
  9. cd from kotlin-library to ios-app folder cd ../ios-app/
  10. Pod install using the command: pod install You'll see something like:
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.

When I build the sample 'ios-app' target: simulator in Xcode, I get the error: fatal error: module 'libPhoneNumber' not found

I have tried other libPhoneNumber pods, such as:

  • libPhoneNumberSwift
  • LTPhoneNumberField Both fail to build using Kotlin's cocoapods plugin, but work as a Pod without Kotlin's cocoapod plugin.

What am I missing?


Solution

  • This particular problem seems to be caused by the dash in the pod's name. There was already an issue reported on GitHub. For now, it's recommended to workaround this problem by re-naming the module. Changing your kotlin-library/build.gradle.kts like

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

    should help. Please give it a try and tell here or on GH if it works.