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

Pallaw Pathak

10/03/2023, 1:16 PM
errorlog.txt
Hello guys, I am using Compose Multiplatform project create through official template. Now I want to include a new shared module. I was trying to add it through android studio new module dialog and choose Regular framework for IOS distribution. Unfortunatly its not working for me.
c

Cherrio LLC

10/03/2023, 2:02 PM
Can you post your configuration??
build.gradle.kts
p

Pallaw Pathak

10/03/2023, 10:00 PM
@Cherrio LLC sure Library module configuration.
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
    targetHierarchy.default()

    android {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "pwUiKmm"
        }
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                //put your multiplatform dependencies here
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
    }
}
Shared Module Configuration
Copy code
plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("org.jetbrains.compose")
}

kotlin {
    androidTarget()

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

            export(project(":pwUiKmm"))
        }
    }

    sourceSets {

        val androidxActivityVersion = extra["androidx.activity.version"] as String
        val androidxAppCompatVersion = extra["androidx.appcompat.version"] as String
        val androidxCoreVersion = extra["androidx.core.version"] as String

        val commonMain by getting {
            dependencies {
                implementation(compose.runtime)
                implementation(compose.foundation)
                implementation(compose.material)
                @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
                implementation(compose.components.resources)
                api(project(":pwUiKmm"))
            }
        }
        val androidMain by getting {
            dependencies {
                api("androidx.activity:activity-compose:${androidxActivityVersion}")
                api("androidx.appcompat:appcompat:${androidxAppCompatVersion}")
                api("androidx.core:core-ktx:${androidxCoreVersion}")
            }
        }
        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)
        }
    }
}

android {
    compileSdk = (findProperty("android.compileSdk") as String).toInt()
    namespace = "xyz.penpencil.unigo"

    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)
    }
}