0

我创建了 XCFramework MyFramework 并尝试按照说明将其连接到 KMM https://kotlinlang.org/docs/mobile/add-dependencies.html#add-a-framework-without-cocoapods

MyFramework.xcframowork 被放置在 KotlinMultiplatform 项目的根目录中

我的 .def 文件如下所示:

language = Objective-C
modules = MyFramework
package = MyFramework

在 build.gradle.kts 文件中我写:

kotlin {
android()
iosX64 {
    compilations.getByName("main") {
        val MyFramework by cinterops.creating {
            // Path to .def file
            defFile("src/nativeInterop/cinterop/MyFramework.def")

            compilerOpts("-framework", "MyFramework", "-F/")
        }
        //val anotherInterop by cinterops.creating { /* ... */ }
    }

    binaries {
        framework {
            baseName = "shared"
        }
    }

    binaries.all {
        // Tell the linker where the framework is located.
        linkerOpts("-framework", "MyFramework", "-F/")
    }
}

但是当我为 iOS 编译 KMM 项目时,它给我写了错误:

Task :shared:cinteropEventBusTypesIosX64 FAILED
Exception in thread "main" java.lang.Error: /var/folders/8h/_7cdkbh56b3fc72xbkjpk4nd218xjp/T/8209547019177661418.m:1:9: fatal error: module 'MyFramework' not found

我想我在 compilerOpts("-framework", "MyFramework", "-F/") 中写了错误的路径,但可能是另一个原因。

4

1 回答 1

1

On compilerOpts("-framework", "MyFramework", "-F/") you must write your path before your framework (write all path).

For example if your MyFramework.framework dir is on path: /MyDisk/MyProyects/MyKotlinProject/MyFramework.framework Your compilerOpts (and your linkerOpts) must be: compilerOpts("-framework", "MyFramework", "-F/MyDisk/MyProyects/MyKotlinProject")

于 2021-01-29T02:21:11.783 回答