Hallo, I have project with android and jvm as targ...
# ios
a
Hallo, I have project with android and jvm as targets and wanted to add ios, the project uses Kotlin 1.8 🧵
So this's what my common build.gradle looks like:
Copy code
import dev.icerock.gradle.MRVisibility

plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("com.android.library")
    id("kotlin-parcelize")
    id("org.jetbrains.compose")
    id("dev.icerock.mobile.multiplatform-resources")
    id("com.squareup.sqldelight")
    id("com.google.devtools.ksp") version "1.8.0-1.0.9"
}

group = "dev.ahmedmourad.clockwise.common"
version = "1.0-SNAPSHOT"

kotlin {
    android {
        dependencies {
            coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
        }
    }
    jvm("desktop") {
        jvmToolchain(17)
    }
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "common"
            isStatic = true
        }
    }
    cocoapods {
        summary = "Some description for the Common Module"
        homepage = "Link to the Common Module homepage"
        version = "1.0"
        ios.deploymentTarget = "14.1"
        podfile = project.file("../ios/Podfile")
        framework {
            baseName = "common"
        }
    }
    sourceSets {
        val commonMain by getting {
            dependencies {
//...
            }
        }
        val commonTest by getting {
            dependencies {
//...
            }
        }
        val androidMain by getting {
            dependencies {
//...
            }
        }
        val androidUnitTest by getting {
            dependencies {
//...
            }
        }
        val androidInstrumentedTest by getting {
            dependencies {
//...
            }
        }
        val desktopMain by getting {
            dependencies {
//...
            }
        }
        val desktopTest 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)
        }
    }
}
This fails on gradle sync with the following error:
Copy code
A problem occurred configuring project ':common'.
> Could not create task ':common:kspIosMainKotlinMetadata'.
   > class org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile_Decorated cannot be cast to class org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon (org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile_Decorated and org.jetbrains.kotlin.gradle.tasks.KotlinCompileCommon are in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @103c20a6)
If I change the iosMain section to this:
Copy code
val iosMain by creating {
   dependsOn(commonMain)
}
The error changes to this:
This's what my file structure looks like, any ideas?
k
first of all, you are not supposed to register ios frameworks manually if you use cocoapods plugin. the plugin makes it by its own. and it has own the 'framework' block inside 'cocoapods'
a
@Konstantin Tskhovrebov So if I replace this:
Copy code
listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
).forEach { iosTarget ->
    iosTarget.binaries.framework {
        baseName = "common"
        isStatic = true
    }
}
with this:
Copy code
iosX64()
iosArm64()
iosSimulatorArm64()
it fixes the second case where
iosMain
looks like this:
Copy code
val iosMain by creating {
   dependsOn(commonMain)
}
and the build is successful!! If iosMain looks like this tho it still produces the first error:
Copy code
val iosMain by creating {
    dependsOn(commonMain)
    iosX64Main.dependsOn(this)
    iosArm64Main.dependsOn(this)
    iosSimulatorArm64Main.dependsOn(this)
}
this's for the purpose of having one source set for all the ios variations
Just tried this as well, same error:
Copy code
ios()
val iosMain by getting {
    dependsOn(commonMain)
}
j
I'd highly recommend using the new target hierarchy API to define depends on relationships between target and intermediate source sets. It simplifies the configuration and makes it much more readable.
r
Can you build from command line? If it’s only an error on sync then it might be a version mismatch in the IDE plugin
a
@Jeff Lockhart I think it's only available from Kotlin 1.8.20, i'm using 1.8.0 I think it was compose mp preventing me from going higher but can't really remember
@russhwolf I found the source of the issue there was ksp which i was using for the android module as follows:
Copy code
configurations["ksp"].dependencies.add(project.dependencies.create("io.github.raamcosta.compose-destinations:ksp:1.8.42-beta"))
commenting out this line stops the error for now Now though i'm getting this error when building ios:
Copy code
e: java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.ir.declarations.IrFunction
	at org.jetbrains.kotlin.backend.konan.lower.ExpectToActualDefaultValueCopier$copyDefaultArgumentsFromExpectToActual$1.visitValueParameter(ExpectDeclarationsRemoving.kt:227)
I removed all default arguments from all expect functions/classes but that didn't fix it building desktop works fine, i assume android would as well because it did before, so only ios does this
j
Compose MP 1.5.1 supports Kotlin 1.9.10, so you might try updating now.
a
@Jeff Lockhart That actually fixed the error! thank you!
🙌🏼 1