Kotlin native interop linker could not find framework

本小妞迷上赌 提交于 2020-01-22 20:47:22

问题


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

  • added framework to Pods file.
  • ran pod install.
  • created .def file
  • added cinterop config in build.gradle

./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

> Task :app:linkDebugFrameworkIos

ld: framework not found FirebaseDatabase

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

Here is my config in 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"
                }
            }
        }
    }

here is my .def file:

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

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


回答1:


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


来源:https://stackoverflow.com/questions/54047711/kotlin-native-interop-linker-could-not-find-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!