Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin native interop linker could not find framework

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

enter image description here

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

like image 951
oleg.semen Avatar asked Jan 05 '19 00:01

oleg.semen


1 Answers

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
like image 156
Nikolay Igotti Avatar answered Nov 19 '22 12:11

Nikolay Igotti