Hello guys. I’m using Kotlin 1.3.20 and gradle 5.1...
# kotlin-native
d
Hello guys. I’m using Kotlin 1.3.20 and gradle 5.1 (along with serialization 0.10.0) in a MPP (Android & iOS). I need to import a custom framework (aka MyUtils) but when I run
./gradlew clean build
I got the following error:
Copy code
> Task :common:linkTestDebugExecutableIOS
ld: framework not found MyUtils
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
Here is the iOS part of my
build.gradle
file:
Copy code
kotlin {
    targets {
        fromPreset(presets.iosArm32, 'iOS') {
            def frameworksDir = "${projectDir}/Frameworks"
            
            binaries {
                framework("p2p_common") {
                    linkerOpts "-F${frameworksDir}"
                }
            }
            compilations.main.extraOpts '-Xembed-bitcode-marker'
            compilations.main.cinterops {
                MyUtils {
                    defFile "src/iOSMain/c_interop/MyUtilsFramework.def"
                    packageName "com.acme.utils"
                    includeDirs "${frameworksDir}/MyUtils.framework/Headers"
                }
            }
        }
        fromPreset(presets.android, 'android')
    }
	...
MyUtilsFramework.def
Copy code
language = Objective-C
headers = MyUtils-Swift.h
compilerOpts = -framework MyUtils
linkerOpts = -framework MyUtils
excludeDependentModules = true
I can see the
p2p-common-cinterop-MyUtils.klib
is generated and actually I can see the classes of the framework from the kotlin code inside the folder
iOSMain
but as I said before the build fails. Has anyone a clue why this happens and how I can fix this problem?
d
I think you have to also add
linkerOpts "-F${frameworksDir}"
to the
compilations.test {}
block.
Or
compilations.test.linkerOpts "-F${frameworksDir}"
.
😍 1
When you specify
linkerOpts
in gradle, they don't get added to the klib, it's only used for "compilation". So all the users of your klib would have to redeclare the
linkerOpts
in their target compilations.
👍 1
d
You are right, after adding
compilations.test.linkerOpts "-F${frameworksDir}"
it works. Thanks a lot @Dominaezzz 🤜🤛