So Im trying to build a project using kotlin multiplatform, I managed to integrate with database/ktor etc but the problem is when I need some dependency from cocoapods. I've seen that starting with kotlin 1.4 xcode is not required to build such a dependency (however even tho it was failing unless I installed xcode on my machine). But to the point, everytime I add a pod section inside cocoapods in build.gradle.kts my sync is failing with:
Exception in thread "main" java.lang.Error: /var/folders/6p/0kpnx2mj22589gthf1dddjwhtr2_tq/T/15810392041507337443.m:1:9: fatal error: module 'AFNetworking' not found
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:506)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:264)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:74)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':example:cinteropAFNetworkingIos'.
> Process 'command '/Applications/Android Studio 4.2 Preview.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
When I launch podspec it is generated correctly, my build gradle files: Top one:
buildscript {
ext.kotlin_version = "1.4.31"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0-beta06"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:1.4.31"
classpath "com.squareup.sqldelight:gradle-plugin:1.4.4"
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url "https://kotlin.bintray.com/kotlinx" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And the one with cocoapods:
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
kotlin("native.cocoapods")
id("com.android.library")
id("kotlin-android-extensions")
id("com.squareup.sqldelight")
}
kotlin {
android()
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {}
version = "1.0.0"
cocoapods {
summary = "This is sample Summary"
homepage = "Home URL"
pod("AFNetworking")
pod("FirebaseAnalytics")
}
val coroutinesVersion = "1.3.9-native-mt"
val serializationVersion = "1.0.0-RC"
val ktorVersion = "1.5.3"
val sqlDelightVersion = "1.4.4"
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation("com.squareup.sqldelight:runtime:$sqlDelightVersion")
}
}
val androidMain by getting {
dependencies {
implementation("androidx.core:core-ktx:1.3.2")
implementation("io.ktor:ktor-client-android:$ktorVersion")
implementation("com.squareup.sqldelight:android-driver:$sqlDelightVersion")
implementation("com.jakewharton.timber:timber:4.7.1")
}
}
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
implementation("com.squareup.sqldelight:native-driver:$sqlDelightVersion")
}
}
}
}
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
}
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
}
Maybe someone already found solution to this?