Kotlin native interop linker could not find framework
Asked Answered
R

1

8

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 ?

Romanfleuve answered 5/1, 2019 at 0:3 Comment(0)
E
1

There are two problematic moments here:

Epsilon answered 5/1, 2019 at 11:35 Comment(5)
Thanks @Nikolay. Regarding full path to headers it's quite obvious, I've been trying to do this but it could not resolve imports. For instance Firebase.h starts with #import <FirebaseCore/FirebaseCore.h> but FirebaseCore.h placed under iosApp/Pods/FirebaseCore/Firebase/Core/Public/ folder.Romanfleuve
Another quite strange thing is that FIRAnalyticsConnector.framework, FirebaseAnalytics.framework, FirebaseCoreDiagnostics.framework, FirebaseInstanceID.framework and GoogleAppMeasurement.framework in my Pods folder although I did not install these pods. FirebaseDatabase.framework I found in /Users/oleg/Library/Developer/Xcode/DerivedData/iosApp-dhmxgbkvemesnaamasxaqqyuqyox/Build/Products/Debug-iphonesimulator/FirebaseDatabase/ folder. Now when I'm specifying this framework I'm getting some Undefined symbols for architecture x86_64: errors (there are quite a few of them).Romanfleuve
BTW there are linkerOpts in both .gradle and .def files. Are they the same ?Romanfleuve
One more question: What about transitive dependencies ? Firebase consists of few libs/frameworks like Core, Database, Firestore, Messaging etc. They depend on each other. Is it enough to specify one of them I'm using ? Or should I specify all of them ?Romanfleuve
Linker options from .def and Gradle pluginare concatenated essentially.Epsilon

© 2022 - 2024 — McMap. All rights reserved.