Kotlin本机互操作链接器找不到框架 [英] Kotlin native interop linker could not find framework

查看:161
本文介绍了Kotlin本机互操作链接器找不到框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Kotlin Multiplatform项目中使用cocoapods框架. 所以我

I'm trying to use cocoapods framework in Kotlin Multiplatform project. So I

  • 将框架添加到Pods文件.
  • 运行pod安装.
  • 创建了.def文件
  • build.gradle
  • 中添加了cinterop配置
  • added framework to Pods file.
  • ran pod install.
  • created .def file
  • added cinterop config in build.gradle

./gradlew cinteropFirebaseIos成功运行.它生成.klib,因此我可以看到kotlin代码中的类. 但是,当我尝试运行iOS应用时,构建失败并显示以下消息:

./gradlew cinteropFirebaseIos runs successfully. It generates .klib so I can see classes in kotlin code. But when I'm trying to run iOS app build fails with message:

显示最近的消息

Showing Recent Messages

>任务:app:linkDebugFrameworkIos

> Task :app:linkDebugFrameworkIos

ld:找不到框架FirebaseDatabase

ld: framework not found FirebaseDatabase

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld调用报告的错误

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors

这是我在build.gradle

    fromPreset(presets.iosX64, 'ios') {
        compilations.main {
            outputKinds('FRAMEWORK')
            cinterops {
                firebase {
                    def proj = "${System.getProperty("user.home")}/Projects/kmpp"
                    def pods = "${proj}/iosApp/Pods"

                    defFile "${proj}/app/src/iosMain/c_interop/libfirebase.def"

                    includeDirs "${pods}/Firebase",
                            "${pods}/Firebase/CoreOnly/Sources",
                            "${pods}/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework/Headers"
                }
            }
        }
    }

这是我的.def文件:

language = Objective-C
headers = /Users/oleg/Projects/klug/crckalculator/iosApp/Pods/FirebaseCore/Firebase/Core/Public/FIRApp.h /Users/oleg/Projects/klug/crckalculator/iosApp/Pods/FirebaseDatabase/Firebase/Database/Public/FIRDatabase.h /Users/oleg/Projects/klug/crckalculator/iosApp/Pods/FirebaseCore/Firebase/Core/Public/FirebaseCore.h

compilerOpts = -framework FirebaseDatabase
linkerOpts = -framework FirebaseDatabase

我该如何找出问题所在?我是否错过了.def文件中的某些内容?在build.gradle吗?

How can I figure out what is wrong ? Did I miss something in .def file ? In build.gradle ?

推荐答案

这里有两个有问题的时刻:

There are two problematic moments here:

  • full paths to C headers in .def file are usually not desirable, instead passing includeDirs to Firebase installation, like in https://github.com/JetBrains/kotlin-native/blob/c7c566ce0f12221088a8908b6dc8e116c56a931b/samples/gtk/build.gradle#L22 would be helpful
  • linking problem comes from the similar issue - linker just got no idea where to look for framework libraries, so passing to compilations.main.linkerOpts smth like -F /Users/oleg/Projects/klug/crckalculator/iosApp/Pods/FirebaseCore/ shall help, see for example https://github.com/JetBrains/kotlin-native/blob/c7c566ce0f12221088a8908b6dc8e116c56a931b/samples/videoplayer/build.gradle#L15

这篇关于Kotlin本机互操作链接器找不到框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆