Hi everyone, I am having issues with Objective-C i...
# multiplatform
s
Hi everyone, I am having issues with Objective-C interop in Kotlin
I have the following swift code: @objc public enum FirebaseAIErrorObjc: Int { case server = 0 case promptBlocked = 1 case responseStopped = 2 case serialization = 3 case invalidAPIKey = 4 case quotaExceeded = 5 case unsupportedUserLocation = 6 case serviceDisabled = 7 case contentBlocked = 8 } I import it into my kmp code as such:
Copy code
cocoapods {
    ios.deploymentTarget = libs.versions.ios.deploymentTarget.get()
    framework {
        baseName = "FirebaseAI" // Not FirebaseAIBridge due to ld: can't link a dylib with itself. same install_name as dylib being built
    }
    pod("FirebaseAIBridge") {
        source = git("<https://github.com/SeanChinJunKai/FirebaseAIBridge|https://github.com/SeanChinJunKai/FirebaseAIBridge>") {
            branch = "main"
        }
        extraOpts += listOf("-compiler-option", "-fmodules")
    }
}
But FirebaseAIErrorObjc is unresolved
I have another enum from previous commits that gets resolved @objc public enum ContentModalityObjc: Int { case unspecified = 0 case text = 1 case image = 2 case video = 3 case audio = 4 case document = 5 public static func from(_ modality: ContentModality) -> ContentModalityObjc { switch modality.rawValue { case ContentModality.text.rawValue: return .text case ContentModality.image.rawValue: return .image case ContentModality.video.rawValue: return .video case ContentModality.audio.rawValue: return .audio case ContentModality.document.rawValue: return .document default: return .unspecified } } }
It shows up in build/cocoapods folder but im not sure why I cannot import it into iosMain
f
Hi, it’s not the cocoapods source that is important, it’s the generated cinterop file (.knm) who is! look inside
build/classes/kotlin/commonizer/..._x64)/fr.frankois944_library-cinterop-appleDeps/default/linkdata
did you try the spm way ?
s
@François its not inside either. It is working with another enum of same format tho
f
try a full clean build or disable the gradle cache
s
btw thanks for introducing ur spm library, i might use it to distriubte using spm too but not for now
how can i disable the gradle cache? Is it
Copy code
kotlin.native.cacheKind.iosSimulatorArm64=none
kotlin.native.cacheKind.iosArm64=none
f
yes and also
Copy code
org.gradle.caching=true -> false
org.gradle.configuration-cache=true -> false
s
thank you ill try it out
im really hoping for direct swift interop with kotlin
now it doesnt work again lmao
f
I gave up on cocoapods; I can’t help you much about using custom pods.
maybe you should use a local one instead of remote one during your devs
s
Hi @Andrey Yastrebov, could you please take a look at this? The swift code is inside this repo: https://github.com/SeanChinJunKai/FirebaseAIBridge
a
take a look at this
What exactly do you want me to look at?
s
It’s the FirebaseAIError.swift file
i’m pretty sure the declaration is correct but i’m not sure why it won’t show up in iosMain
however adding new swift classes with @objc notation does show up in iosMain
you can ignore it
i got it to work