I want to use moko-socketio library but when I want to add libraries based on the document guide, the libraries have errors. I have the same errors when my project libraries are the type of Regular libraries rather than CocoaPods How can I fix it? Is it the correct place where I added libraries?
Shared build.gradle:
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
}
kotlin {
android()
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"
}
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting
val androidTest 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.sn.myapplication"
compileSdk = 32
defaultConfig {
minSdk = 21
targetSdk = 32
}
}
dependencies {
commonMainApi("dev.icerock.moko:socket-io:0.3.0")
commonMainApi("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.1")
}
// HERE IS ERROR
cocoaPods {
podsProject = file("../ios-app/Pods/Pods.xcodeproj") // here should be path to Pods xcode project
pod("mokoSocketIo", onlyLink = true)
}
CodePudding user response:
Icerock uses their own plugins to configure KMM projects like https://plugins.gradle.org/plugin/dev.icerock.mobile.multiplatform.cocoapods. If you add this to the main gradle file:
buildscript {
repositories {
// your repos
}
dependencies {
classpath("dev.icerock:mobile-multiplatform:0.14.2")
// other dependencies
and this to the shared library gradle file:
plugins {
// other plugins
id("dev.icerock.mobile.multiplatform.cocoapods")
id("dev.icerock.mobile.multiplatform.ios-framework")
}
Then it should compile.
However, socket-io
is not compiled for the iosSimulatorArm64
target as you can see here: https://github.com/icerockdev/moko-socket-io/blob/master/socket-io/build.gradle.kts. The target ios()
is a shortcut for iosX64()
and iosArm64()
and the simulator target needs to be added on top of that to support running the app on simulators (compare https://kotlinlang.org/docs/multiplatform-share-on-platforms.html#use-target-shortcuts). In other words, you need to remove that target from your app and run the app on a real device.