firebase-kotlin-sdk icon indicating copy to clipboard operation
firebase-kotlin-sdk copied to clipboard

Cannot build iOS app: framework not found FirebaseFirestore

Open MartinRajniak opened this issue 2 years ago • 8 comments

Hi, I am trying to integrate FirebaseFirestore, like this:

sourceSets {
    val commonMain by getting {
        dependencies {
            ...
            implementation("dev.gitlive:firebase-firestore:1.4.3")
        }
    }
    

I am using new KMM project from IDE wizard with iOS and Android modules for apps, and shared module for common code.

And when I am trying to build iOS app I am getting this error:

Task :shared:linkDebugFrameworkIos FAILED e: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors

The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1. output: ld: framework not found FirebaseFirestore

Any pointer about how to debug this would be helpful. Thanks

MartinRajniak avatar Oct 05 '21 16:10 MartinRajniak

This is what I had to do for SDK in env. For Carthage and CocoaPods there are other solutions available:

`val xcf = XCFramework() val libs = listOf( "FirebaseAuth.xcframework", "GTMSessionFetcher.xcframework", "FirebaseCore.xcframework", "FirebaseCoreDiagnostics.xcframework", "FirebaseAnalytics.xcframework", "GoogleAppMeasurement.xcframework", "FirebaseInstallations.xcframework", "GoogleDataTransport.xcframework", "GoogleUtilities.xcframework", "PromisesObjC.xcframework", "nanopb.xcframework", "FirebaseFunctions.xcframework" ) val nativeFrameworkPaths = projectDir.resolve(System.getenv("FIREBASE_SDK")).listFiles() .filter { it.isDirectory } .flatMap { it.listFiles().filter { it.isDirectory && libs.contains(it.name) } }

    ios()
    iosArm64 {
        binaries.framework {
            baseName = "Module"
            xcf.add(this)

            val libraryIdentifier = "ios-arm64_armv7"
            linkerOpts(nativeFrameworkPaths.map { "-F$it/$libraryIdentifier" })
            linkerOpts("-ObjC")
        }
    }
    val iosSims = listOf(iosX64(), iosSimulatorArm64())
    configure(iosSims) {
        binaries.framework {
            baseName = "Module"
            xcf.add(this)

            val libraryIdentifier = "ios-arm64_i386_x86_64-simulator"
            linkerOpts(nativeFrameworkPaths.map { "-F$it/$libraryIdentifier" })
            linkerOpts("-ObjC")
        }
    }
} `

hohteri avatar Oct 05 '21 17:10 hohteri

Hello, I have tried this solution but I have gotten this error

System.getenv("FIREBASE_SDK") must not be null
	at org.gradle.kotlin.dsl.execution.InterpreterKt$locationAwareExceptionFor$2.invoke(Interpreter.kt:563)
	at org.gradle.kotlin.dsl.execution.InterpreterKt.locationAwareExceptionFor(Interpreter.kt:570)
	at org.gradle.kotlin.dsl.execution.InterpreterKt.locationAwareExceptionHandlingFor(Interpreter.kt:536)
	at org.gradle.kotlin.dsl.execution.InterpreterKt.access$locationAwareExceptionHandlingFor(Interpreter.kt:1)
	at org.gradle.kotlin.dsl.execution.Interpreter$ProgramHost.handleScriptException(Interpreter.kt:385)

eric-ampire avatar Oct 11 '21 22:10 eric-ampire

  1. Download Firebase as a zip file: https://firebase.google.com/docs/ios/setup#frameworks
  2. Unzip
  3. Set env variable FIREBASE_SDK to point where you unzipped it e.g. export FIREBASE_SDK=~/Downloads/Firebase

hohteri avatar Oct 12 '21 02:10 hohteri

Why does the project using this library need to download Firebase SDK?

I thought it should come with this library - or as a transitive dependency of the library.

What is the meaning of the cart files then? https://github.com/GitLiveApp/firebase-kotlin-sdk/blob/master/firebase-functions/src/nativeInterop/cinterop/Cartfile

MartinRajniak avatar Oct 16 '21 14:10 MartinRajniak

There are generally four ways of having dependencies in an Xcode project:

  • cocoapods
  • Carthage
  • SPM
  • File system

my example uses file system through an env variable. Unfortunately I can’t help you with the others.

hohteri avatar Oct 16 '21 18:10 hohteri

Looks like it makes sense to provide a sample for library users, to showcase iOS setup. Me myself is still struggling to find the best way to link iOS Firebase frameworks to KMM. @nbransby @Reedyuk tagging you just in case you can help here.

sdelaysam avatar Nov 02 '21 06:11 sdelaysam

For what it's worth, my iOS setup is working fine out of the box if I add Firebase/Firestore as a Cocoapods dependency (even directly in the Podfile which Kotlin doesn't know about, not in the gradle cocoapods {} config).

walkingbrad avatar Nov 09 '21 23:11 walkingbrad

For what it's worth, my iOS setup is working fine out of the box if I add Firebase/Firestore as a Cocoapods dependency (even directly in the Podfile which Kotlin doesn't know about, not in the gradle cocoapods {} config).

Same

alperenbabagil avatar Dec 21 '21 23:12 alperenbabagil

@walkingbrad I have a similar issue with remote-config requiring "firebaseABTesting", but just adding that as a pod results in Cinterop issues

Failed to generate cinterop for :mcdonalds-umbrella-module:cinteropFirebaseABTestingIosArm64: Process 'command '/Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java'' finished with non-zero exit value 134
Exception in thread "Thread-3" kotlin.NotImplementedError: An operation is not implemented: support enum forward declarations: enum ABTExperimentPayloadExperimentOverflowPolicy
	at org.jetbrains.kotlin.native.interop.indexer.NativeIndexImpl.getEnumDefAt(Indexer.kt:321)
	at org.jetbrains.kotlin.native.interop.indexer.NativeIndexImpl.indexDeclaration(Indexer.kt:877)
	at org.jetbrains.kotlin.native.interop.indexer.IndexerKt$indexDeclarations$1$2.indexDeclaration(Indexer.kt:1208)
	at org.jetbrains.kotlin.native.interop.indexer.UtilsKt$indexTranslationUnit$1$indexerCallbacks$1$4.invoke(Utils.kt:561)
	at org.jetbrains.kotlin.native.interop.indexer.UtilsKt$indexTranslationUnit$1$indexerCallbacks$1$4.invoke(Utils.kt:558)
	at kotlinx.cinterop.JvmCallbacksKt$createStaticCFunctionImpl$$inlined$ffiClosureImpl$3.accept(JvmCallbacks.kt:510)

casvanluijtelaar avatar Oct 13 '22 10:10 casvanluijtelaar

I'm having the same issue with "FirebaseABTesting". I'm using Swift Package Manager.

lammertw avatar Oct 18 '22 18:10 lammertw

I am also facing the same issue. I've tried adding the dependency manually:

  • Using SPM
  • Cocoapods (which told me that the dependency already existed if I added via Gradle and it simply didn't work if independent)
  • Carthage (although I might not have set it correctly since I am not very familiar with it).

But I always end up having the same error 🥲

The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
ld: framework not found FirebaseAuth

Could someone provide a sample/guide/gist on how to configure the build.gradle so that we can use FirebaseFirestore or any other dependency in common code and target iOS?

I've tried to follow #111 #208 #322 #326 with no luck 🥲. @casvanluijtelaar created a minimum reproducible example here https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/326#issuecomment-1285496883, not sure if anyone has been able to check it.

Any help would be greatly appreciated 🙇🏻‍♂️

izadiegizabal avatar Nov 14 '22 09:11 izadiegizabal

Hello there, I face the same issue

ld: framework not found FirebaseABTesting
Task :shared:linkReleaseFrameworkIosX64 FAILED

Are there any plans to release a new version soon as I see it uses kotlin 1.6.10 and version 1.8 is around the corner. Thanks in advance for any replay.

RudolfHladik avatar Dec 09 '22 12:12 RudolfHladik

I resolved the issue and made a sample project: https://github.com/leoull/KMM-FirebaseAuth

leoull avatar Dec 16 '22 21:12 leoull

Can you guys try release 1.8.0, the switch over to cocoapods plugin should make the resolution easier

Reedyuk avatar Apr 05 '23 10:04 Reedyuk

thanks for the update @Reedyuk! i solved the issue last time by creating a new project from scratch and selecting cooapods from the kmm plugin setup wizard. not sure why the default framework option + setting cocoapods myself for this was not working (i guess i was setting up something wrong)

the new update seems to be working well, but i don't know if it would have helped back when i was stuck. thanks for the update and keeping this repo alive!

izadiegizabal avatar Apr 09 '23 09:04 izadiegizabal

setting isStatic = true in build.gradle fixed this

Kashif-E avatar May 16 '23 08:05 Kashif-E