samuele794

    samuele794

    4 months ago
    Hi, just for info: for use this library https://github.com/gitliveapp/firebase-kotlin-sdk i need add other configuration (exclude google json/plist) for use in test? I imported it in KaMPKit and when i start compile for iOSTest continually doesn't find something from Framework
    t

    Tijl

    4 months ago
    Kotlin Multiplatform is very bad with Kotlin/Native and testing. you have to provide the libraries you want to link to the test binary yourself. Here is how firebase-kotlin-sdk does this itself: https://github.com/GitLiveApp/firebase-kotlin-sdk/blob/master/firebase-firestore/build.gradle.kts#L95
    samuele794

    samuele794

    4 months ago
    hi, thank for response, i tentative update the script but now i have this ploblem
    this is my current gradle
    import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
    
    plugins {
        kotlin("multiplatform")
        kotlin("native.cocoapods")
        id("kotlinx-serialization")
        id("com.android.library")
        id("com.squareup.sqldelight")
    }
    
    android {
        compileSdk = libs.versions.compileSdk.get().toInt()
        defaultConfig {
            minSdk = libs.versions.minSdk.get().toInt()
            targetSdk = libs.versions.targetSdk.get().toInt()
            testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        }
        testOptions {
            unitTests {
                isIncludeAndroidResources = true
            }
        }
    
        lint {
            isWarningsAsErrors = true
            isAbortOnError = true
        }
    }
    
    version = "1.2"
    
    val org.jetbrains.kotlin.konan.target.KonanTarget.archVariant: String
        get() = if (this is org.jetbrains.kotlin.konan.target.KonanTarget.IOS_X64 || this is org.jetbrains.kotlin.konan.target.KonanTarget.IOS_SIMULATOR_ARM64) {
            "ios-arm64_x86_64-simulator"
        } else {
            "ios-arm64_armv7"
        }
    
    
    android {
        configurations {
            create("androidTestApi")
            create("androidTestDebugApi")
            create("androidTestReleaseApi")
            create("testApi")
            create("testDebugApi")
            create("testReleaseApi")
        }
    }
    
    kotlin {
        android()
    //    ios()
    //    iosSimulatorArm64()
    
        fun nativeTargetConfig(): KotlinNativeTarget.() -> Unit = {
            val nativeFrameworkPaths = listOf(
                rootProject.project("shared").projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/")
            ).plus(
                listOf(
                    "FirebaseAnalytics",
                    "FirebaseCore",
                    "FirebaseCoreDiagnostics",
                    "FirebaseInstallations",
                    "GoogleAppMeasurement",
                    "GoogleAppMeasurementIdentitySupport",
                    "GoogleDataTransport",
                    "GoogleUtilities",
                    "nanopb",
                    "PromisesObjC"
                ).map {
                   val projectDir = rootProject.project("shared").projectDir
    
                    val folder =
                        projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
    
                    if (folder.exists()) {
                        folder
                    } else {
                        projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/ios-arm64_i386_x86_64-simulator")
                    }
                }
            ).plus(
                listOf(
                    "FirebaseAuth",
                    "GTMSessionFetcher"
                ).map {
                    projectDir.resolve("src/nativeInterop/cinterop/Carthage/Build/$it.xcframework/${konanTarget.archVariant}")
                }
            )
            binaries {
                getTest("DEBUG").apply {
                    linkerOpts(nativeFrameworkPaths.map { "-F$it" })
                    linkerOpts("-ObjC")
                }
            }
    
    //        compilations.getByName("main") {
    //            cinterops.create("FirebaseAuth") {
    //                compilerOpts(nativeFrameworkPaths.map { "-F$it" })
    //                extraOpts = listOf("-compiler-option", "-DNS_FORMAT_ARGUMENT(A)=", "-verbose")
    //            }
    //        }
        }
    
    
        ios(configure = nativeTargetConfig())
        iosSimulatorArm64(configure = nativeTargetConfig())
    
    
    
    
        sourceSets {
            all {
                languageSettings.apply {
                    optIn("kotlin.RequiresOptIn")
                    optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
                }
            }
        }
    
        // Enable concurrent sweep phase in new native memory manager. (This will be enabled by default in 1.7.0)
        // <https://kotlinlang.org/docs/whatsnew1620.html#concurrent-implementation-for-the-sweep-phase-in-new-memory-manager>
        targets.withType<KotlinNativeTarget> {
            binaries.all {
                freeCompilerArgs += "-Xgc=cms"
            }
        }
    
        sourceSets {
            val commonMain by getting {
                dependencies {
                    implementation(libs.koin.core)
                    implementation(libs.coroutines.core)
                    implementation(libs.sqlDelight.coroutinesExt)
                    implementation(libs.bundles.ktor.common)
                    implementation(libs.touchlab.stately)
                    implementation(libs.multiplatformSettings.common)
                    implementation(libs.kotlinx.dateTime)
                    api(libs.touchlab.kermit)
    
                    implementation("dev.gitlive:firebase-common:1.6.1")
                    implementation("dev.gitlive:firebase-auth:1.6.1")
    
    
                }
            }
            val commonTest by getting {
                dependencies {
                    implementation(libs.bundles.shared.commonTest)
                }
            }
            val androidMain by getting {
                dependencies {
                    implementation(libs.androidx.lifecycle.viewmodel)
                    implementation(libs.sqlDelight.android)
                    implementation(libs.ktor.client.okHttp)
                }
            }
            val androidTest by getting {
                dependencies {
                    implementation(libs.bundles.shared.androidTest)
                }
            }
            val iosMain by getting {
                dependencies {
                    implementation(libs.sqlDelight.native)
                    implementation(libs.ktor.client.ios)
                }
            }
            val iosTest by getting
            val iosSimulatorArm64Main by getting {
                dependsOn(iosMain)
            }
            val iosSimulatorArm64Test by getting {
                dependsOn(iosTest)
            }
        }
    
        sourceSets.matching { it.name.endsWith("Test") }
            .configureEach {
                languageSettings.optIn("kotlin.time.ExperimentalTime")
            }
    
        cocoapods {
            summary = "Common library for the KaMP starter kit"
            homepage = "<https://github.com/touchlab/KaMPKit>"
            framework {
                isStatic = false // SwiftUI preview requires dynamic framework
            }
            ios.deploymentTarget = "12.4"
            podfile = project.file("../ios/Podfile")
        }
    }
    
    sqldelight {
        database("KaMPKitDb") {
            packageName = "co.touchlab.kampkit.db"
        }
    }