Is there an updated guide on how to use an objecti...
# kotlin-native
y
Is there an updated guide on how to use an objective c framework (such as AFNetworking) in kotlin native using the
kotlin-platform-native
plugin? The closest thing I could find was this issue: https://github.com/JetBrains/kotlin-native/issues/1764 but it’s using
konan
I’ve been trying for a while but I keep getting error:
Copy code
ld: framework not found xxxxx
This is what we have in our gradle file:
Copy code
components.main{
    dependencies{
        cinterop('Framework'){
            def productsDir = new File("Framework").absolutePath
            compilerOpts "-F${productsDir}"
            linkerOpts "-F${productsDir}"
            includeDirs "${productsDir}/Framework.framework/Headers"
        }
    }
}
d
add
extraOpts "-linker-options", "-F${productsDir}"
to the
compilations.main
block.
🙏 1
d
This is how I'm building AFNetworking(note, I don't use cocoapods). Deffile:
Copy code
language = Objective-C
headers = AFURLSessionManager.h AFURLResponseSerialization.h AFHTTPSessionManager.h
compilerOpts = -framework AFNetworking
linkerOpts = -framework AFNetworking
You can add more headers as you see fit. I only needed those three in my project. Gradle:
Copy code
components.main {

    def productsDir = new File("").absolutePath

    targets = ['ios_arm64', 'ios_x64']
    outputKinds = [EXECUTABLE]

    allTargets {
        linkerOpts '-rpath', '@executable_path/Frameworks'
        linkerOpts "-F${productsDir}"
    }

    dependencies {
        cinterop('AFNetworking'){
            packageName 'com.afnetworking'
            compilerOpts "-F${productsDir}"
            linkerOpts "-F${productsDir}"
            includeDirs{
                allHeaders "${productsDir}/AFNetworking.framework/Headers"
            }
        }
    }
}
y
Thankyou! This worked