KoalaPlot / koalaplot-core

Koala Plot is a Compose Multiplatform based charting and plotting library written in Kotlin
https://koalaplot.github.io/
MIT License
373 stars 18 forks source link

IOS supported or not? #37

Closed vdcast closed 7 months ago

vdcast commented 7 months ago

Hello! I've added lib to commonMain dependencies and it seems works well on Android app. When I'm trying to build an app via Xcode - it says Build Failed with error:

Could not find "org.jetbrains.kotlin.native.platform.Symbols" in [/Users/vdcast/111/DEV/Projects/MoneyWorksPersonal, /Users/vdcast/.konan/klib, /Users/vdcast/.konan/kotlin-native-prebuilt-macos-x86_64-1.9.10/klib/common, /Users/vdcast/.konan/kotlin-native-prebuilt-macos-x86_64-1.9.10/klib/platform/ios_arm64]

Do I need to add in in Xcode libraries? If yes - how to do it? Please, help me add it to IOS target correctly, ty!

Here is my build.gradle shared module:

`plugins { kotlin("multiplatform") id("com.android.library") id("org.jetbrains.compose") id("com.squareup.sqldelight") }

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

targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).all {
    binaries.withType(org.jetbrains.kotlin.gradle.plugin.mpp.Framework::class.java).all {
        export("dev.icerock.moko:mvvm-core:0.16.1")
    }
}

listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
).forEach { iosTarget ->
    iosTarget.binaries.framework {
        baseName = "shared"
        isStatic = true
    }
}

sourceSets {
    val commonMain by getting {
        dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material3)
            @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
            implementation(compose.components.resources)

            implementation("androidx.datastore:datastore-preferences-core:1.1.0-dev01")

            implementation("com.squareup.sqldelight:runtime:1.5.5")
            implementation("com.squareup.sqldelight:coroutines-extensions:1.5.5")
            implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")

            implementation("org.jetbrains.kotlinx:atomicfu:0.17.3")

            implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")

            implementation("io.github.koalaplot:koalaplot-core:0.5.2")
        }
    }
    val androidMain by getting {
        dependencies {
            api("androidx.activity:activity-compose:1.8.0")
            api("androidx.appcompat:appcompat:1.6.1")
            api("androidx.core:core-ktx:1.12.0")

            implementation("com.squareup.sqldelight:android-driver:1.5.5")
        }
    }
    val iosX64Main by getting
    val iosArm64Main by getting
    val iosSimulatorArm64Main by getting
    val iosMain by creating {
        dependencies {
            implementation("com.squareup.sqldelight:native-driver:1.5.5")
        }
        dependsOn(commonMain)
        iosX64Main.dependsOn(this)
        iosArm64Main.dependsOn(this)
        iosSimulatorArm64Main.dependsOn(this)
    }
}

}

android { compileSdk = (findProperty("android.compileSdk") as String).toInt() namespace = "com.vdcast.moneyworkspersonal"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")

defaultConfig {
    minSdk = (findProperty("android.minSdk") as String).toInt()
}
compileOptions {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
    jvmToolchain(17)
}

}

sqldelight { database("AppDatabase") { packageName = "com.vdcast.moneyworkspersonal.data.database" sourceFolders = listOf("sqldelight") } }

dependencies { implementation("androidx.compose.material3:material3:1.1.2") implementation("androidx.core:core:1.10.1") commonMainApi("dev.icerock.moko:mvvm-core:0.16.1") commonMainApi("dev.icerock.moko:mvvm-compose:0.16.1") commonMainApi("dev.icerock.moko:mvvm-flow:0.16.1") commonMainApi("dev.icerock.moko:mvvm-flow-compose:0.16.1") }`

and build.gradle project:

buildscript { dependencies { classpath("com.android.tools.build:gradle:8.1.2") classpath("com.squareup.sqldelight:gradle-plugin:1.5.5") classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.17.3") } } plugins { kotlin("multiplatform").apply(false) id("com.android.application").apply(false) id("com.android.library").apply(false) id("org.jetbrains.compose").apply(false) }

allprojects { apply(plugin = "kotlinx-atomicfu") }

repositories { mavenCentral() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") }

gsteckman commented 7 months ago

It should work - I don't have Apple devices but others have tested it. One user has an app that you can find here to compare with your build: https://github.com/joreilly/FantasyPremierLeague

The error you are getting is for a missing "org.jetbrains.kotlin.native.platform.Symbols", so it looks like this isn't related to Koala Plot. Are you able to get a Compose iOS application to run without using Koala Plot?

vdcast commented 7 months ago

yes, I can't build a project in Xcode once I've added the lib to commonMain dependencies. Same code works well on Android, but on IOS it doesn't.

Maybe I need to add the lib in Xcode manually? It seems like something can't share the lib to IOS target

gsteckman commented 7 months ago

Looks like this may be a bug in Kotlin multiplatform 1.9.10, see https://youtrack.jetbrains.com/issue/KT-63805. I would try upgrading to the latest, which is 1.9.22.

vdcast commented 7 months ago

thanks for advice! I changed kotlin version to 1.9.20 and compose multiplatform version to 1.5.11. Now it works.