https://kotlinlang.org logo
t

Tom Pratt

12/29/2020, 6:03 PM
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: 1. Cloned the KMM with cocoapods sample app. https://github.com/Kotlin/kotlin-with-cocoapods-sample 2. Gradle sync and build the project. Everything succeeds. 3. Add the NearbyMessages pod in build.gradle.kts just above the AFNetworking line...
pod("NearbyMessages")
4. Now when I gradle sync I get the following error.
> 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 <http://Studio.app/Contents/jre/jdk/Contents/Home/bin/java|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.
m

mkrussel

12/29/2020, 6:32 PM
Not sure if this is what you are experiencing, but I ran into cases where the name of the module does not match the name of the pod. The pod method defaults to using the same name, but there should be a way to override it.
t

Tom Pratt

12/29/2020, 6:56 PM
I saw a stackoverflow about that but after looking at the podspec file it didnt seem like that was the case here. Although I'm not exactly familiar with them since this is my first time using it! https://github.com/CocoaPods/Specs/blob/master/Specs/f/b/9/NearbyMessages/1.1.1/NearbyMessages.podspec.json
m

mkrussel

12/30/2020, 12:55 PM
don't know much about cocoa pods or frameworks, but if you look at the `module.modulemap`file in the framework installed by the cocoapod you should see the name of the module. I don't think the module name needs to be in the podspec so looking there will not help.
t

Tom Pratt

12/30/2020, 6:43 PM
I looked in that file but but it just looks like a very few lines of boilerplate? Nothing that looks like any of the individual pods added.
Copy code
framework module kotlin_library {
  umbrella header "placeholder.h"

  export *
  module * { export * }
}
m

mkrussel

12/30/2020, 8:19 PM
So I think the module name is
kotlin_library
and not
NearbyMessages
like gradle is looking for. Seems like a strange name though. Is that the module file for the framework installed when you ran
pod install
or is that an output from gradle?
t

Tom Pratt

12/30/2020, 8:44 PM
I think this is kotlin gradle output since it's part of the kotlin cocoapods sample app linked above, which is a pure gradle project with no xcode files
Should be quite easy to reproduce with the steps posted if anyone feels like giving it a try 😁
8 Views