Closed jnelle closed 1 year ago
Could you post your full build gradle file, there is something not right with the targets. I noticed you include the cio library in the common, but i was under the impression this is jvm/android only. Having the full build gradle will give me a better idea
Sure!
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
id("com.rickclephas.kmp.nativecoroutines")
id("com.google.devtools.ksp")
}
kotlin {
android {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
iosX64()
iosArm64()
iosSimulatorArm64()
cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
version = "1.0"
ios.deploymentTarget = "14.1"
podfile = project.file("../iosApp/Podfile")
framework {
baseName = "shared"
isStatic = true
export(project(":domain"))
pod("FirebaseAuth")
pod("FirebaseFirestore")
pod("FirebaseCore")
}
extraSpecAttributes["resources"] =
"['src/commonMain/resources/**', 'src/iosMain/resources/**']"
}
kotlin.sourceSets.all {
languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("io.ktor:ktor-client-core:2.3.0")
implementation("io.ktor:ktor-client-content-negotiation:2.3.0")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.0")
implementation("io.ktor:ktor-client-cio:2.3.0")
api("dev.gitlive:firebase-auth:1.8.1")
implementation("dev.gitlive:firebase-firestore:1.8.1")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
implementation("io.github.aakira:napier:2.6.1")
api(project(":domain"))
api(project(":courses"))
api(project(":auth"))
api("com.rickclephas.kmm:kmm-viewmodel-core:1.0.0-ALPHA-8")
api("io.insert-koin:koin-core:3.4.0")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-android:2.2.4")
implementation("io.ktor:ktor-client-core:2.3.0")
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
api("io.insert-koin:koin-android:3.4.0")
api("com.rickclephas.kmm:kmm-viewmodel-core:1.0.0-ALPHA-8")
}
}
val androidUnitTest by getting
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
val iosX64Test by getting
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
}
}
android {
namespace = "com.my.app"
compileSdk = 33
defaultConfig {
minSdk = 29
}
}
There is a number of red flags with your build gradle, i have tried to tidy it up a bit.
Pro tip: Try to put all your dependancies in common main, this is the whole principle of KMM, only the platform specific dependancies should live in the platform source set.
The issue you were probably getting was where you put the 'pod' annotation, i moved it out one layer.
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
id("com.rickclephas.kmp.nativecoroutines")
id("com.google.devtools.ksp")
}
kotlin {
android {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
ios()
iosSimulatorArm64()
cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
version = "1.0"
ios.deploymentTarget = "14.1"
podfile = project.file("../iosApp/Podfile")
framework {
baseName = "shared"
isStatic = true
export(project(":domain"))
}
pod("FirebaseAuth")
pod("FirebaseFirestore")
pod("FirebaseCore")
extraSpecAttributes["resources"] =
"['src/commonMain/resources/**', 'src/iosMain/resources/**']"
}
kotlin.sourceSets.all {
languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("io.ktor:ktor-client-core:2.3.0")
implementation("io.ktor:ktor-client-content-negotiation:2.3.0")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.0")
api("dev.gitlive:firebase-auth:1.8.1")
implementation("dev.gitlive:firebase-firestore:1.8.1")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
implementation("io.github.aakira:napier:2.6.1")
api(project(":domain"))
api(project(":courses"))
api(project(":auth"))
api("com.rickclephas.kmm:kmm-viewmodel-core:1.0.0-ALPHA-8")
api("io.insert-koin:koin-core:3.4.0")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-cio:2.3.0")
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
}
}
val androidUnitTest by getting
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-darwin:2.3.0")
}
}
val iosSimulatorArm64Main by getting
iosSimulatorArm64Main.dependsOn(iosMain)
val iosTest by getting
val iosSimulatorArm64Test by getting
iosSimulatorArm64Test.dependsOn(iosTest)
}
}
android {
namespace = "com.my.app"
compileSdk = 33
defaultConfig {
minSdk = 29
}
}
you may need to add this to your gradle properties:
kotlin.mpp.enableCInteropCommonization=true
kotlin.native.cacheKind=none
So i have found your issue, the solution is to do the following:
pod("FirebaseFirestore", linkOnly = true)
I resolved the error by adding the firebase packages via SPM and removed them from the cocoapods section in build gradle
Hello there,
first of all thank you for that awesome KMM lib!
I set up a new KMM project and used cocoapods for iOS dependencies. When I try to build it for iOS I got the following error:
java.lang.Error: Linking globals named 'knifunptr_cocoapods_FirebaseFirestore2_FirebaseFirestoreVersionNumber_getter': symbol multiply defined!
You see the full stacktrace under build.gradle.kts.
My build.gradle.kts in /shared is the following:
Full stacktrace:
Does anyone know how to fix this?