Can't add libPhoneNumber-ios pod in a KMM project

214 Views Asked by At

I'm trying to add google's libPhoneNumber to a KMM project. I'm using an expect/actual implementation, and on the Android side all is working fine.

However, I'm struggling to get it working on the iOS side.

I'm trying to use libPhoneNumber-ios (https://github.com/iziz/libPhoneNumber-iOS) but I can't get the pod to install when I add it to the cocoapods block in my build.gradle.kts file.

When I add pod("libPhoneNumber-iOS", version = "~> 0.9.15", moduleName = "libPhoneNumber_iOS" ) to the cocoapods block the Gradle project fails to sync.

Executing of 'xcodebuild -project Pods.xcodeproj -scheme libPhoneNumber-iOS -sdk iphoneos -configuration Release' failed with code 65 and message: 

Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project Pods.xcodeproj -scheme libPhoneNumber-iOS -sdk iphoneos -configuration Release

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES

Build settings from command line:
    SDKROOT = iphoneos17.0

ComputeTargetDependencyGraph
note: Building targets in dependency order
note: Target dependency graph (1 target)
    Target 'libPhoneNumber-iOS' in project 'Pods' (no dependencies)

GatherProvisioningInputs

CreateBuildDescription

ClangStatCache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk /Users/username/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/iphoneos17.0-21A325-1e1d10ddc0bdcd738a98873f48b793a5.sdkstatcache
    cd /Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/Pods/Pods.xcodeproj
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang-stat-cache /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk -o /Users/username/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/iphoneos17.0-21A325-1e1d10ddc0bdcd738a98873f48b793a5.sdkstatcache

/Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'libPhoneNumber-iOS' from project 'Pods')
Ld /Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/Release-iphoneos/libPhoneNumber-iOS/libPhoneNumber_iOS.framework/libPhoneNumber_iOS normal (in target 'libPhoneNumber-iOS' from project 'Pods')
    cd /Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/Pods
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Xlinker -reproducible -target arm64-apple-ios8.0 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.0.sdk -Os -L/Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/EagerLinkingTBDs/Release-iphoneos -L/Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/Release-iphoneos/libPhoneNumber-iOS -F/Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/EagerLinkingTBDs/Release-iphoneos -F/Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/Release-iphoneos/libPhoneNumber-iOS -filelist /Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/Pods.build/Release-iphoneos/libPhoneNumber-iOS.build/Objects-normal/arm64/libPhoneNumber_iOS.LinkFileList -install_name @rpath/libPhoneNumber_iOS.framework/libPhoneNumber_iOS -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/Pods.build/Release-iphoneos/libPhoneNumber-iOS.build/Objects-normal/arm64/libPhoneNumber_iOS_lto.o -fobjc-arc -fobjc-link-runtime -lz -framework CoreTelephony -framework CoreTelephony -framework Foundation -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/Pods.build/Release-iphoneos/libPhoneNumber-iOS.build/Objects-normal/arm64/libPhoneNumber_iOS_dependency_info.dat -o /Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/Release-iphoneos/libPhoneNumber-iOS/libPhoneNumber_iOS.framework/libPhoneNumber_iOS
clang: error: SDK does not contain 'libarclite' at the path '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a'; try increasing the minimum deployment target



2023-10-16 16:40:01.319 xcodebuild[34338:331711] [MT] DVTPlugInManager: Required plug-in compatibility UUID EB1EF21B-E756-4D3D-A6EA-E9C57D8C1924 for Kotlin.ideplugin (org.kotlinlang.xcode.kotlin) not present
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
{ platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00008112-001608560C88201E }
{ platform:macOS, arch:arm64, variant:Mac Catalyst, id:00008112-001608560C88201E }
{ platform:macOS, arch:x86_64, variant:Mac Catalyst, id:00008112-001608560C88201E }
{ platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }
{ platform:macOS, variant:Mac Catalyst, name:Any Mac }
{ platform:iOS Simulator, id:27F1CFF4-3C82-4CDD-AC43-66937C41B6F0, OS:17.0, name:iPad (10th generation) }
{ platform:iOS Simulator, id:27F1CFF4-3C82-4CDD-AC43-66937C41B6F0, OS:17.0, name:iPad (10th generation) }
{ platform:iOS Simulator, id:FBAEFA8B-AA4B-4A9A-AB48-44DB19780AB9, OS:17.0, name:iPad Air (5th generation) }
{ platform:iOS Simulator, id:FBAEFA8B-AA4B-4A9A-AB48-44DB19780AB9, OS:17.0, name:iPad Air (5th generation) }
{ platform:iOS Simulator, id:EDCE4234-16C7-4E18-AB4A-F97F9ED9B9B0, OS:17.0, name:iPad Pro (11-inch) (4th generation) }
{ platform:iOS Simulator, id:EDCE4234-16C7-4E18-AB4A-F97F9ED9B9B0, OS:17.0, name:iPad Pro (11-inch) (4th generation) }
{ platform:iOS Simulator, id:B78E1D23-D5F3-479B-AC6B-7D8131CC3FDC, OS:17.0, name:iPad Pro (12.9-inch) (6th generation) }
{ platform:iOS Simulator, id:B78E1D23-D5F3-479B-AC6B-7D8131CC3FDC, OS:17.0, name:iPad Pro (12.9-inch) (6th generation) }
{ platform:iOS Simulator, id:3B48062B-B00A-44DB-8235-F920DCCCC1AD, OS:17.0, name:iPad mini (6th generation) }
{ platform:iOS Simulator, id:3B48062B-B00A-44DB-8235-F920DCCCC1AD, OS:17.0, name:iPad mini (6th generation) }
{ platform:iOS Simulator, id:D688F1AA-8130-4098-A215-72E57552367A, OS:17.0, name:iPhone 15 }
{ platform:iOS Simulator, id:D688F1AA-8130-4098-A215-72E57552367A, OS:17.0, name:iPhone 15 }
{ platform:iOS Simulator, id:A76DCA95-1BDA-44ED-99FF-847B3E998C0A, OS:17.0, name:iPhone 15 Plus }
{ platform:iOS Simulator, id:A76DCA95-1BDA-44ED-99FF-847B3E998C0A, OS:17.0, name:iPhone 15 Plus }
{ platform:iOS Simulator, id:D30626A7-A549-46F3-98BD-ACB25A7A63CE, OS:17.0, name:iPhone 15 Pro }
{ platform:iOS Simulator, id:D30626A7-A549-46F3-98BD-ACB25A7A63CE, OS:17.0, name:iPhone 15 Pro }
{ platform:iOS Simulator, id:46BC51F6-0CB7-43DC-BAA3-C8D0DB999346, OS:17.0, name:iPhone 15 Pro Max }
{ platform:iOS Simulator, id:46BC51F6-0CB7-43DC-BAA3-C8D0DB999346, OS:17.0, name:iPhone 15 Pro Max }
{ platform:iOS Simulator, id:9115D513-B05C-4D89-B40B-14B61BE82805, OS:17.0, name:iPhone SE (3rd generation) }
{ platform:iOS Simulator, id:9115D513-B05C-4D89-B40B-14B61BE82805, OS:17.0, name:iPhone SE (3rd generation) }
** BUILD FAILED **


The following build commands failed:
    Ld /Users/username/AndroidStudioProjects/KMMProject/shared/build/cocoapods/synthetic/IOS/build/Release-iphoneos/libPhoneNumber-iOS/libPhoneNumber_iOS.framework/libPhoneNumber_iOS normal (in target 'libPhoneNumber-iOS' from project 'Pods')
(1 failure)


If I add the pod to the podfile and run pod install, then it installs fine, and I can access it in xcode /Swift, but I can't import cocoapods.libPhoneNumber_iOS. in iOSMain.

Note: I'm renaming the pod based on this question/answer: libPhonenumber (from Google) on iOS in a Kotlin Native project, but it doesn't make a difference if I leave this out, I get the same errors.

I have a suspicion that this is down to minimum deployment targets (there's a hint in the message above

clang: error: SDK does not contain 'libarclite' at the path '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a'; try increasing the minimum deployment target.

If I open the generated podfile at shared/build/cocoapods/synthetic/ios, the iOS Deployment Target for the libPhoneNumber-iOS target is 8.0 (I'm using Xcode 15, so my min deployment target is 12.0).

However, I have no idea how to resolve this! My ios.deployment target is set to 14.1 in my build.gradle.kts cocoapods block (and everywhere else):

  cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        version = "1.0"
        ios.deploymentTarget = "14.1"
        podfile = project.file("../iosApp/Podfile")
         pod("libPhoneNumber-iOS", version = "~> 0.9.15", moduleName = "libPhoneNumber" )
        framework {
            baseName = "shared"
            isStatic = true
            export("dev.icerock.moko:resources:${rootProject.extra["mokoVersion"]}")
            export("dev.icerock.moko:graphics:0.9.0")
        }
    }

Update I've now managed to get the Gradle project to sync, the c-interop gets created correctly and I can use the lipPhoneNumber APIs in the iOSMain module.

Adding the following to my build.gradle.kts did it:

 tasks.withType<org.jetbrains.kotlin.gradle.targets.native.tasks.PodGenTask>().configureEach {
        doLast {

            val xcodeprojFiles = listOf(
                "Pods/Pods.xcodeproj",
                "synthetic.xcodeproj",
            )

            for (xcodeprojFile in xcodeprojFiles) {
                val file = project.buildDir.resolve("cocoapods/synthetic/${family.name}/$xcodeprojFile/project.pbxproj")
                setIosDeploymentTarget(file)
            }
        }
    }
---
fun setIosDeploymentTarget(
    xcodeprojFile: File,
    source: String = "8.0",
    target: String = "14.1",
) {
    val lines = xcodeprojFile.readLines()
    val out = xcodeprojFile.bufferedWriter()
    out.use {
        for (line in lines) {
            out.write(line.replace("IPHONEOS_DEPLOYMENT_TARGET = $source;", "IPHONEOS_DEPLOYMENT_TARGET = $target;"))
            out.write(("\n"))
        }
    }
}

However, the iOS app won't build. I get hundreds of errors, everything that uses the shared module. If I "Jump to definition" on my "import shared", it takes me to an empty file.

So, I'm still unable to use this.

Any thoughts?

0

There are 0 best solutions below