I wonder if anyone can help me to add a cocoapod to a kotlin native module, not having much luck so far! The library is Google's NearbyMessages API. https://developers.google.com/nearby/messages/ios/get-started
So far I have:
pod("NearbyMessages")
> Task :kotlin-library:cinteropNearbyMessagesIosArm64 FAILED
Exception in thread "main" java.lang.Error: /var/folders/t7/gwvnk41x66g5kmr7s7y8thdw0000gn/T/6648793494349780018.m:1:9: fatal error: module 'NearbyMessages' not found
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:507)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:265)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:73)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
Execution failed for task ':kotlin-library:cinteropNearbyMessagesIosArm64'.
> Process 'command '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
I was able to install the cocoapod using a podfile and pod install. With no KMM involved. I've tried all sorts of random stuff besides but these are the steps that seem like they should work.
Here is the podspec file for NearbyMessages: https://github.com/CocoaPods/Specs/blob/master/Specs/f/b/9/NearbyMessages/1.1.1/NearbyMessages.podspec.json
JB guys have answered you here.
I report the answer here for better indexing:
Hello, Tom Pratt, thank you for the report! As far as I can see, the problem is caused by the fact
NearbyMessages
pod consists of a static Objective-C library, not a framework. It has no module.modulemap, so the cinterop cannot interpret it correctly. Changingbuild/cocoapods/defs/NearbyMessages.def
's content to have a headers option instead of module let me executecinterop
manually, but I'm not sure it can be done inside of the Cocoapods Integration.
As a manual workaround they suggests:
Also, to make this manual workaround a bit more usable, you can try to tune the Gradle task generating this
.def
file. Just add
tasks.named<DefFileTask>("generateDefNearbyMessages").configure {
doLast {
outputFile.writeText("""
language = Objective-C
headers = GNSMessages.h
""")
}
}