Hi all, I am trying to build a kotlin multiplatfo...
# multiplatform
s
Hi all, I am trying to build a kotlin multiplatform library which is using cocoapods to pull through GRPCClient and Protobuf. We wanted to make this a library so we dont have to run the pod install step all the time. When we pull in the library into a parent project via commonMain.dependencies it will fail to build the iosApp unless we also include the same cocoapods block we used to generate the library.
Copy code
ld: warning: Could not find or use auto-linked framework 'GRPCClient': framework 'GRPCClient' not found
ld: warning: Could not find or use auto-linked framework 'Protobuf': framework 'Protobuf' not found
ld: warning: Could not parse or use implicit file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/SwiftUICore.framework/SwiftUICore.tbd': cannot link directly with 'SwiftUICore' because product being built is not an allowed client of it
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_GRPCCall2", referenced from:
       in ComposeApp[2](ComposeApp.framework.o)
  "_OBJC_CLASS_$_GRPCMutableCallOptions", referenced from:
       in ComposeApp[2](ComposeApp.framework.o)
  "_OBJC_CLASS_$_GRPCRequestOptions", referenced from:
       in ComposeApp[2](ComposeApp.framework.o)
ld: symbol(s) not found for architecture arm64
I can see in the External Libraries section that the GRPCClient and Protobuf klibs are being pulled in (though they are in separate klib files). Here is the gradle m2 folder for iosarm64
Copy code
ls ~/.m2/repository/com/example/grpc-iosarm64/0.0.0-34-g08af418-SNAPSHOT         
grpc-iosarm64-0.0.0-34-g08af418-SNAPSHOT-cinterop-GRPCClient.klib
grpc-iosarm64-0.0.0-34-g08af418-SNAPSHOT-cinterop-Protobuf.klib
grpc-iosarm64-0.0.0-34-g08af418-SNAPSHOT-kotlin_resources.kotlin_resources.zip
grpc-iosarm64-0.0.0-34-g08af418-SNAPSHOT-metadata.jar
grpc-iosarm64-0.0.0-34-g08af418-SNAPSHOT-sources.jar
grpc-iosarm64-0.0.0-34-g08af418-SNAPSHOT.klib
grpc-iosarm64-0.0.0-34-g08af418-SNAPSHOT.module
grpc-iosarm64-0.0.0-34-g08af418-SNAPSHOT.pom
maven-metadata-local.xml
I was under the impression that we would be able to package up a library in such a way that we would not need to explicictly include the cocoapods dependencies seeing as the cinterop klibs are all being generated. Is there a way to statically link the cocoapods dependencies into a multiplatform library?
f
Hello, you can use in the cocoapods config block
Copy code
framework {
            // Required properties
            // Framework name configuration. Use this property instead of deprecated 'frameworkName'
            baseName = "MyFramework"

            // Optional properties
            // Specify the framework linking type. It's dynamic by default.
            isStatic = false
            // Dependency export
            // Uncomment and specify another project module if you have one:
            // export(project(":<your other KMP module>"))
            transitiveExport = false // This is default.
        }
> When we pull in the library into a parent project via commonMain.dependencies it will fail to build the iosApp unless we also include the same cocoapods block we used to generate the library. Yes, that’s totally normal. I’m the author of spm4Kmp and came across of this kind of issue. The thing is, even you succeed on the linking step. ressources will be missing like Bundle or xcprivacy. The cocoapods integration on the xcode side is really important. The other solution is to create a KMP module exported into a binary xcframework who contains all needed ressources, then add it to your project.
s
Hi @François thanks for your reply, I have been trying to work out how to export my library into an xcframework and then consume it in my mulitplatform project. have you got an example anywhere of this working? having a terrible time trying to make it work.
f
Hey, It will be difficult to remotely help you, this case is kind of complex to manage
@Sam O'Donovan I did something who can help you, it will resolve half of your issues, but it’s a good start