Cocoapods cinterop & platform.CoreGraphics package

Hello everyone,

I have a problem when importing cocoapods libraries on the latest Kotlin release 1.7.20. I have a project integrating KMM for mobile platforms. Until recently integrating cocoapods via native.cocoapods plugin used to link platform.CoreGraphics lib to the generated .knm file. Thus making functions like CGSize automatically linked to the platform lib instead of building its own classes. But lately I have upgraded to the latest Kotlin features and this behaviour seems to have disappear. Here is an example of what used to work for me and what I would like to return to if possible:

Here is the gradle definition:

build.gradle.kts

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    kotlin("plugin.serialization")
    id("com.android.library")
}

kotlin {
    android()
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    cocoapods {
        version = "1.0.0"
        summary = "..."
        homepage = "..."
        ios.deploymentTarget = "10.0"
        podfile = project.file("../../../appleSystem/Podfile")

        framework {
            ...
        }

        xcodeConfigurationToNativeBuildType["CUSTOM_DEBUG"] = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG
        xcodeConfigurationToNativeBuildType["CUSTOM_RELEASE"] = org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.RELEASE

        pod("UIColor-HTMLColors") { version = "~> 1.0.0" }
        pod("PinLayout") { version = "~> 1.10.3" }
        pod ("MarqueeLabel"){ version = "~> 4.3.0"}
        pod ("BadgeSwift") { version = "~> 8.0"}
        pod("Reachability") { version = "~> 3.2"}
    }

    sourceSets {
        ...
    }
}

android {
    ...
}

This still synchronize and compile. Though, if you take BadgeSwift pod for instance (others have the same issue), the generated knm file will look something like this:

// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

package cocoapods.BadgeSwift

public typealias CGFloatVar = kotlinx.cinterop.DoubleVarOf<cocoapods.BadgeSwift.CGFloat>

public typealias swift_float3Var = kotlinx.cinterop.Vector128VarOf<cocoapods.BadgeSwift.swift_float3>

public typealias char16_tVar = kotlinx.cinterop.UShortVarOf<cocoapods.BadgeSwift.char16_t>

public typealias swift_uint3Var = kotlinx.cinterop.Vector128VarOf<cocoapods.BadgeSwift.swift_uint3>

public typealias swift_double2 = kotlin.native.Vector128

public typealias CGFloat = kotlin.Double

public typealias swift_uint4Var = kotlinx.cinterop.Vector128VarOf<cocoapods.BadgeSwift.swift_uint4>

public typealias char16_t = platform.posix.uint_least16_t

public typealias swift_int4 = kotlin.native.Vector128

public typealias swift_int3 = kotlin.native.Vector128

public typealias swift_uint3 = kotlin.native.Vector128

public typealias swift_float4 = kotlin.native.Vector128

public typealias swift_float3 = kotlin.native.Vector128

public typealias char32_tVar = kotlinx.cinterop.UIntVarOf<cocoapods.BadgeSwift.char32_t>

public typealias swift_uint4 = kotlin.native.Vector128

public typealias swift_int4Var = kotlinx.cinterop.Vector128VarOf<cocoapods.BadgeSwift.swift_int4>

public typealias char32_t = platform.posix.uint_least32_t

public typealias swift_float4Var = kotlinx.cinterop.Vector128VarOf<cocoapods.BadgeSwift.swift_float4>

public typealias swift_int3Var = kotlinx.cinterop.Vector128VarOf<cocoapods.BadgeSwift.swift_int3>

public typealias swift_double2Var = kotlinx.cinterop.Vector128VarOf<cocoapods.BadgeSwift.swift_double2>

public expect interface UIMenuLeafProtocolMeta : platform.darwin.NSObjectProtocolMeta {
}

public open expect class UIWindowSceneGeometryPreferences : platform.darwin.NSObject {
    public expect companion object : cocoapods.BadgeSwift.UIWindowSceneGeometryPreferencesMeta, kotlinx.cinterop.ObjCClassOf<cocoapods.BadgeSwift.UIWindowSceneGeometryPreferences> {
    }

    @kotlin.commonizer.ObjCCallable public constructor() { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun init(): cocoapods.BadgeSwift.UIWindowSceneGeometryPreferences? { /* compiled code */ }
}

public final expect class CGSize public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
    public expect companion object : kotlinx.cinterop.CStructVar.Type {
    }

    public expect final var height: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */

    public expect final var width: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */
}

public expect interface UIPopoverPresentationControllerSourceItemProtocol : platform.darwin.NSObjectProtocol {
}

public open expect class UIWindowSceneGeometryMeta : platform.darwin.NSObjectMeta, platform.Foundation.NSCopyingProtocolMeta {
    protected constructor() { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun alloc(): cocoapods.BadgeSwift.UIWindowSceneGeometry? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun allocWithZone(zone: kotlinx.cinterop.CPointer<cnames.structs._NSZone>?): cocoapods.BadgeSwift.UIWindowSceneGeometry? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun new(): cocoapods.BadgeSwift.UIWindowSceneGeometry? { /* compiled code */ }
}

public open expect class UISceneWindowingBehaviorsMeta : platform.darwin.NSObjectMeta {
    protected constructor() { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun alloc(): cocoapods.BadgeSwift.UISceneWindowingBehaviors? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun allocWithZone(zone: kotlinx.cinterop.CPointer<cnames.structs._NSZone>?): cocoapods.BadgeSwift.UISceneWindowingBehaviors? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun new(): cocoapods.BadgeSwift.UISceneWindowingBehaviors? { /* compiled code */ }
}

public expect interface UIMenuLeafProtocol : platform.darwin.NSObjectProtocol {
    @kotlin.commonizer.ObjCCallable public abstract expect fun attributes(): platform.UIKit.UIMenuElementAttributes /* = kotlin.ULong */

    @kotlin.commonizer.ObjCCallable public abstract expect fun discoverabilityTitle(): kotlin.String?

    @kotlin.commonizer.ObjCCallable public abstract expect fun image(): platform.UIKit.UIImage?

    @kotlin.commonizer.ObjCCallable public abstract expect fun performWithSender(sender: kotlin.Any?, target: kotlin.Any?): kotlin.Unit

    @kotlin.commonizer.ObjCCallable public abstract expect fun presentationSourceItem(): cocoapods.BadgeSwift.UIPopoverPresentationControllerSourceItemProtocol?

    @kotlin.commonizer.ObjCCallable public abstract expect fun sender(): kotlin.Any?

    @kotlin.commonizer.ObjCCallable public abstract expect fun setAttributes(attributes: platform.UIKit.UIMenuElementAttributes /* = kotlin.ULong */): kotlin.Unit

    @kotlin.commonizer.ObjCCallable public abstract expect fun setDiscoverabilityTitle(discoverabilityTitle: kotlin.String?): kotlin.Unit

    @kotlin.commonizer.ObjCCallable public abstract expect fun setImage(image: platform.UIKit.UIImage?): kotlin.Unit

    @kotlin.commonizer.ObjCCallable public abstract expect fun setState(state: platform.UIKit.UIMenuElementState): kotlin.Unit

    @kotlin.commonizer.ObjCCallable public abstract expect fun setTitle(title: kotlin.String): kotlin.Unit

    @kotlin.commonizer.ObjCCallable public abstract expect fun state(): platform.UIKit.UIMenuElementState

    @kotlin.commonizer.ObjCCallable public abstract expect fun title(): kotlin.String
}

public open expect class UIWindowSceneGeometryPreferencesMeta : platform.darwin.NSObjectMeta {
    protected constructor() { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun alloc(): cocoapods.BadgeSwift.UIWindowSceneGeometryPreferences? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun allocWithZone(zone: kotlinx.cinterop.CPointer<cnames.structs._NSZone>?): cocoapods.BadgeSwift.UIWindowSceneGeometryPreferences? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun new(): cocoapods.BadgeSwift.UIWindowSceneGeometryPreferences? { /* compiled code */ }
}

public open expect class UISceneWindowingBehaviors : platform.darwin.NSObject {
    public expect companion object : cocoapods.BadgeSwift.UISceneWindowingBehaviorsMeta, kotlinx.cinterop.ObjCClassOf<cocoapods.BadgeSwift.UISceneWindowingBehaviors> {
    }

    @kotlin.commonizer.ObjCCallable public constructor() { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun init(): cocoapods.BadgeSwift.UISceneWindowingBehaviors? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun isClosable(): kotlin.Boolean { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun isMiniaturizable(): kotlin.Boolean { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setClosable(closable: kotlin.Boolean): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setMiniaturizable(miniaturizable: kotlin.Boolean): kotlin.Unit { /* compiled code */ }
}

public open expect class BadgeSwift : platform.UIKit.UILabel {
    public expect companion object : cocoapods.BadgeSwift.BadgeSwiftMeta, kotlinx.cinterop.ObjCClassOf<cocoapods.BadgeSwift.BadgeSwift> {
    }

    @kotlin.commonizer.ObjCCallable public constructor(coder: platform.Foundation.NSCoder) { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public constructor(frame: kotlinx.cinterop.CValue<cocoapods.BadgeSwift.CGRect>) { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public constructor() { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun badgeColor(): platform.UIKit.UIColor { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun borderColor(): platform.UIKit.UIColor { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun borderWidth(): cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun cornerRadius(): cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun drawRect(rect: kotlinx.cinterop.CValue<cocoapods.BadgeSwift.CGRect>): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun init(): cocoapods.BadgeSwift.BadgeSwift { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun initWithCoder(aDecoder: platform.Foundation.NSCoder): cocoapods.BadgeSwift.BadgeSwift? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun initWithFrame(frame: kotlinx.cinterop.CValue<cocoapods.BadgeSwift.CGRect>): cocoapods.BadgeSwift.BadgeSwift { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun insets(): kotlinx.cinterop.CValue<cocoapods.BadgeSwift.CGSize> { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun prepareForInterfaceBuilder(): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setBadgeColor(badgeColor: platform.UIKit.UIColor): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setBorderColor(borderColor: platform.UIKit.UIColor): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setBorderWidth(borderWidth: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setCornerRadius(cornerRadius: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setInsets(insets: kotlinx.cinterop.CValue<cocoapods.BadgeSwift.CGSize>): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setShadowColorBadge(shadowColorBadge: platform.UIKit.UIColor): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setShadowOffsetBadge(shadowOffsetBadge: kotlinx.cinterop.CValue<cocoapods.BadgeSwift.CGSize>): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setShadowOpacityBadge(shadowOpacityBadge: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun setShadowRadiusBadge(shadowRadiusBadge: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */): kotlin.Unit { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun shadowColorBadge(): platform.UIKit.UIColor { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun shadowOffsetBadge(): kotlinx.cinterop.CValue<cocoapods.BadgeSwift.CGSize> { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun shadowOpacityBadge(): cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun shadowRadiusBadge(): cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ { /* compiled code */ }
}

public final expect class CGVector public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
    public expect companion object : kotlinx.cinterop.CStructVar.Type {
    }

    public expect final var dx: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */

    public expect final var dy: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */
}

public final expect class CGRect public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
    public expect companion object : kotlinx.cinterop.CStructVar.Type {
    }

    public expect final val origin: cocoapods.BadgeSwift.CGPoint /* compiled code */

    public expect final val size: cocoapods.BadgeSwift.CGSize /* compiled code */
}

public open expect class BadgeSwiftMeta : platform.UIKit.UILabelMeta {
    protected constructor() { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun alloc(): cocoapods.BadgeSwift.BadgeSwift? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun allocWithZone(zone: kotlinx.cinterop.CPointer<cnames.structs._NSZone>?): cocoapods.BadgeSwift.BadgeSwift? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun appearance(): cocoapods.BadgeSwift.BadgeSwift { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun appearanceForTraitCollection(trait: platform.UIKit.UITraitCollection, whenContainedInInstancesOfClasses: kotlin.collections.List<*>): cocoapods.BadgeSwift.BadgeSwift { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun appearanceForTraitCollection(trait: platform.UIKit.UITraitCollection, whenContainedIn: platform.UIKit.UIAppearanceContainerProtocol?, vararg args: kotlin.Any?): cocoapods.BadgeSwift.BadgeSwift { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun appearanceForTraitCollection(trait: platform.UIKit.UITraitCollection): cocoapods.BadgeSwift.BadgeSwift { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun appearanceWhenContainedIn(ContainerClass: platform.UIKit.UIAppearanceContainerProtocol?, vararg args: kotlin.Any?): cocoapods.BadgeSwift.BadgeSwift { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun appearanceWhenContainedInInstancesOfClasses(containerTypes: kotlin.collections.List<*>): cocoapods.BadgeSwift.BadgeSwift { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun new(): cocoapods.BadgeSwift.BadgeSwift? { /* compiled code */ }
}

public final expect class CGPoint public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
    public expect companion object : kotlinx.cinterop.CStructVar.Type {
    }

    public expect final var x: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */

    public expect final var y: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */
}

public open expect class UIWindowSceneGeometry : platform.darwin.NSObject, platform.Foundation.NSCopyingProtocol {
    public expect companion object : cocoapods.BadgeSwift.UIWindowSceneGeometryMeta, kotlinx.cinterop.ObjCClassOf<cocoapods.BadgeSwift.UIWindowSceneGeometry> {
    }

    @kotlin.commonizer.ObjCCallable public constructor() { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun copyWithZone(zone: kotlinx.cinterop.CPointer<platform.Foundation.NSZone /* = cnames.structs._NSZone */>?): kotlin.Any { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable @kotlin.Deprecated public open external expect fun init(): cocoapods.BadgeSwift.UIWindowSceneGeometry? { /* compiled code */ }

    @kotlin.commonizer.ObjCCallable public open external expect fun interfaceOrientation(): platform.UIKit.UIInterfaceOrientation /* = kotlin.Long */ { /* compiled code */ }
}

public final expect class CGAffineTransform public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
    public expect companion object : kotlinx.cinterop.CStructVar.Type {
    }

    public expect final var a: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */

    public expect final var b: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */

    public expect final var c: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */

    public expect final var d: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */

    public expect final var tx: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */

    public expect final var ty: cocoapods.BadgeSwift.CGFloat /* = kotlin.Double */ /* compiled code */
}

public expect interface UIPopoverPresentationControllerSourceItemProtocolMeta : platform.darwin.NSObjectProtocolMeta {
}

As you can see in the method setInsets for exemple:

    @kotlin.commonizer.ObjCCallable public open external expect fun setInsets(insets: kotlinx.cinterop.CValue<cocoapods.BadgeSwift.CGSize>): kotlin.Unit { /* compiled code */ }

The argument the pod is waiting for is a CGSize that is defined in cocoapods.BadgeSwift. Therefore the package has its own CGSize instead of using the one that is accessible in platform.CoreGraphics. The linkage used to be done automatically before resulting rather in something like that:

    @kotlin.commonizer.ObjCCallable public open external expect fun setInsets(insets: kotlinx.cinterop.CValue<platform.CoreGraphics.CGSize>): kotlin.Unit { /* compiled code */ }

I though I could come back to the old behaviour by overriding the .def file generated for the pod:

tasks.named<org.jetbrains.kotlin.gradle.tasks.DefFileTask>("generateDefBadgeSwift").configure {
    doLast {
        outputFile.writeText("""
            depends = platform.CoreGraphics
            language = Objective-C
            modules = BadgeSwift
        """.trimIndent())
    }
}

but this does not seem to work and I can’t find seem to find any subject related to that matter on the web. Could someone help me understand my problem here please. I am still pretty new to KMM, maybe I should use other def flags to import the CoreGraphics framework ? Am I expecting something that should not have been there in the first place ?

Thank you for your time,
Best regards

Someone from Jetbrains answered my question. If anyone else have the same problem, you can refer to this answer: https://youtrack.jetbrains.com/issue/KT-54738/Cocoapods-cinterop-linking-platformCoreGraphics-package#focus=Comments-27-6577596.0-0