GitLiveApp / firebase-kotlin-sdk

A Kotlin-first SDK for Firebase
https://gitliveapp.github.io/firebase-kotlin-sdk/
Apache License 2.0
979 stars 148 forks source link

ios test task is failing with: "Id: framework not found FirebaseCore" #499

Open Link184 opened 2 months ago

Link184 commented 2 months ago

Steps to reproduce:

  1. add dev.gitlive:firebase-firestore:1.12.0 to common dependencies
  2. optional step to fix normal ios builds: add iosSimilatorArm64().binaries.framework { isStatic = true }
  3. make sure you have at least 1 test defined in commonTest source set
  4. run :myKmpModule:allTests

Notes: The build is failing only on ios test task, another platform tests are running fine. Looks like isStatic and kotlin.mpp.enableCInteropCommonization flags are not not working on test builds

Daeda88 commented 1 month ago

In your project add:

cocoapods {
   pod("FirebaseCore") { version = "10.19.0" }
}

Unfortunately cocoapod dependencies are not transitive so your tests wont be able to find them

PRUJA commented 3 weeks ago

@Daeda88 How achieve it with SPM ?

Daeda88 commented 3 weeks ago

@PRUJA you cannot achieve this with SPM since Kotlin Native has no support for it. The problem with this is not in your iOS project, but rather in the app that gradle builds internally to run tests on. It needs to have the frameworks linked to start, much like your real iOS project. If the cocoapods block is too hefty for you (which I can imagine as it increases build times by a lot) you can manually set it in the block IFF you know the location of your frameworks:

val iosTarget: KotlinNativeTarget.() -> Unit = {
    binaries {
        getTest("DEBUG").apply {
              linkerOpts() // Set link to Framework here
        }
   }
}
iosX64(iosTarget)
iosArm64(iosTarget)
iosSimulatorArm64(iosTarget)
Daeda88 commented 3 weeks ago

In our own project we have a separate repo that simply contains the cocoapods block in gradle, and then use it to retrieve the required LinkerOpts for our project:

https://pl.kotl.in/LaYzHO_uX

Use it as:

val podsToAdd = listOf(// add names of pods to link here)
binaries {
    getTest("DEBUG").apply {
        linkFrameworkSearchPaths(cachedCocoapodsPath) {
            it in podsToAdd
        }
    }
}