https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
m

Maximilian Pröll

11/13/2023, 2:47 PM
Hi, I'm currently working on a compose multiplatform chart library. It's already on mavenCentral (snapshot version). On Android, the app builds and runs without any issues. However, on iOS the build fails with
Copy code
> Task :shared:linkDebugFrameworkIosSimulatorArm64 FAILED
error: Could not find "Compose" in [/Users/max/StudioProjects/compose-multiplatform-pomodoro, /Users/max/.konan/klib, /Users/max/.konan/kotlin-native-prebuilt-macos-aarch64-1.9.10/klib/common, /Users/max/.konan/kotlin-native-prebuilt-macos-aarch64-1.9.10/klib/platform/ios_simulator_arm64]
And this is the build.gradle file of the library:
Copy code
plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.android.library)
    alias(libs.plugins.compose.multiplatform)
    id("maven-publish")
    id("signing")
    id("com.vanniktech.maven.publish") version "0.25.3"
}

kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "17"
            }
        }

        publishLibraryVariants("release", "debug")
    }

    ios{}
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    sourceSets {
        val commonMain by getting {
            dependencies {
                api(compose.runtime)
                api(compose.foundation)
                api(compose.material3)
                api(compose.animation)

                implementation(libs.kotlinx.atomicfu)
            }
        }
        val commonTest by getting {
            dependencies {
                //implementation(libs.kotlin.test)
            }
        }
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by getting {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
    }
}

android {
    namespace = "..."

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlin {
        jvmToolchain(17)
    }

    compileSdk = 34
    defaultConfig {
        minSdk = 26
    }
}

mavenPublishing {
    ...
}
In the app, which uses the library, I simply have added it as a commonMain dependency:
Copy code
api(libs.compose.multiplatform.chart)
What could be the problem here? Why doesn't the task find "Compose"?
d

Dima Avdeev

11/14/2023, 11:32 AM
Are this library open source? Can you please share a link to sources.
n

Nikita Lipsky

11/14/2023, 11:36 AM
Can you tell maven coordinates of your library?
m

Maximilian Pröll

11/14/2023, 11:45 AM
yes, the source code is on GitHub (you can ignore the readme, it needs to be updated): https://github.com/maximilianproell/compose-multiplatform-chart Current version is "2.0.2-SNAPSHOT"
thank you color 1
@Nikita Lipsky Yes, the POM is defined in the build.gradle.kts file, if that's what you mean
oh an here is the app gradle file, in case you need it (https://github.com/maximilianproell/compose-multiplatform-pomodoro/blob/main/shared/build.gradle.kts). I haven't pushed the added dependency though, as the app doesn't build for iOS. I added the dependency for the chart library right to the
commonMain
block.
Any hints on how I could resolve this issue? I also compared my library to other available compose multiplatform libraries, but to my eyes, I'm having the same gradle setup. To my understanding, it should just work on iOS, but I have no clue where to look further.
n

Nikita Lipsky

11/15/2023, 7:02 PM
I haven't pushed the added dependency though, as the app doesn't build for iOS
So what line should I add to reproduce the problem?
m

Maximilian Pröll

11/15/2023, 9:00 PM
Add
implementation("io.github.maximilianproell:compose-multiplatform-chart:2.0.2-SNAPSHOT")
to
commonMain
of any KMP project targeting Android and iOS, observe that the Android App builds and runs successfully, whereas the iOS version does not build, throwing the error message mentioned above.
Ok I was finally able to solve the issue. All I did was set Compose to the newest version 1.5.10 and setting Kotlin to 1.9.20. Now the build for iOS succeeds. Very weird...