https://kotlinlang.org logo
Title
d

darkmoon_uk

01/11/2021, 11:51 PM
Anyone have an experience with diagnosing when
cinterop
fails for a Cocoapod
? No useful output; the Java process exited non-zero 🤷 Knowing what the
cinterop
command line executed by
podImport
task is, would be a help to start diagnosing/tweaking from the command line. Anyone have an example of 'manually' driving cinterop against a Cocoapod?
a

Artyom Degtyarev [JB]

01/12/2021, 10:33 AM
Hello, @darkmoon_uk! Have you tried executing this task from the terminal with
--debug
flag?
d

darkmoon_uk

01/12/2021, 12:05 PM
Hi @Artyom Degtyarev [JB], I haven't had time yet, but I'll try to recreate the
cinterop
call from terminal. As the Cocoapods plugin hides this I'll need to create a best-guess def file to recreate the problem. Is there any shortcut you know of to achieve this? Thanks.
a

Artyom Degtyarev [JB]

01/12/2021, 12:09 PM
I’ve tried on a simple project(the KMM Application from AS wizard, with a simple cocoapods plugin use), calling
./gradlew :shared:podImport --debug
I got this output:
Build operation 'Resolve files of :shared:iosX64SDWebImageCInterop' completed
2021-01-12T13:36:10.043+0300 [INFO] [org.gradle.api.Project] Run tool: "cinterop" with args: -o /Users/artyom.degtyarev/AndroidStudioProjects/WizardBorn/shared/build/classes/kotlin/iosX64/main/shared-cinterop-SDWebImage.klib -target ios_x64 -def /Users/artyom.degtyarev/AndroidStudioProjects/WizardBorn/shared/build/cocoapods/defs/SDWebImage.def -pkg cocoapods.SDWebImage -compiler-option -F/Users/artyom.degtyarev/AndroidStudioProjects/WizardBorn/shared/build/cocoapods/synthetic/iosX64/shared/build/Release-iphonesimulator/AFNetworking -compiler-option -F/Users/artyom.degtyarev/AndroidStudioProjects/WizardBorn/shared/build/cocoapods/synthetic/iosX64/shared/build/Release-iphonesimulator/SDWebImage -compiler-option -F/Users/artyom.degtyarev/AndroidStudioProjects/WizardBorn/shared/build/cocoapods/synthetic/iosX64/shared/Pods/../../../../framework -Xmodule-name com.example.wizardborn:shared-cinterop-SDWebImage
As you can see, .def file should be available at
build/cocoapods/defs
, arguments could also be grabbed from this output.
👌 1
d

darkmoon_uk

01/12/2021, 1:41 PM
Thanks @Artyom Degtyarev [JB]. The
.def
for this Bluedot Point SDK Cocoapod contained only:
language = Objective-C
modules = BluedotPointSDK
So I tried this:
~/.konan/kotlin-native-prebuilt-macos-1.4.21/bin/cinterop -def ./shared/build/cocoapods/defs/BluedotPointSDK.def -staticLibrary ./iosApp/Pods/BluedotPointSDK/PointSDK/BDPointSDK.framework/BDPointSDK 
Exception in thread "main" java.lang.Error: /var/folders/88/ryrlz__94m59h1pnvb2z7zg00000gn/T/13800816599543313007.m:1:9: fatal error: module 'BluedotPointSDK' 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)
...not sure if providing the static library file from within the
.framework
package, as an argument to
-staticLibrary
is what
cinterop
expects, but it seemed reasonable.
I know cinterop works via Objective C ABI and this is a requirement; and I know this SDK to be Objective-C as I developed it myself in previous company; but I contacted that company again to find out if the current devs are interested in making it work in KMP. They very much are 👍 ...and said that they 'might have introduced one or two pure Swift classes in the public headers since'.
a

Artyom Degtyarev [JB]

01/14/2021, 12:58 PM
I’ve played with this pod a little, and can say there are two probems with this. • Pod name differs from the framework name. To deal with it, one should specify
moduleName
to be corresponding to the framework’s name. In this case, your
build.gradle.kts
should contain something like
cocoapods {
        summary = "CocoaPods test library"
        homepage = "<https://github.com/JetBrains/kotlin>"
        pod("BluedotPointSDK", moduleName= "BDPointSDK")
• The second problem is that this framework use
@import
, which needs
-fmodules
flag to be set. This is not supported by the
cinterop
tool at the moment, please see this issue: https://youtrack.jetbrains.com/issue/KT-39120 Unfortunately, the second problem does not have any workarounds(as far as I’m informed).