Hi, When I migrate from binary framework to pod, I...
# multiplatform
v
Hi, When I migrate from binary framework to pod, I have compilation error in Xcode : Cannot add binary podDebugFramework dependency to default fat framework java.lang.IllegalArgumentException: This fat framework already has a binary for architecture
x64
(commonModule for target
ios_x64
) What need clean, that project build correct?
v
I think this is not exactly what need. I migrate to pod module and want to disable binaries module
a
Can you share your build script?
v
Copy code
plugins {
    kotlin("multiplatform")
    kotlin("native.cocoapods")
    id("kotlinx-serialization")
    id("com.android.library")
    id("com.squareup.sqldelight")
    id("org.jetbrains.compose") version "1.4.1"
}

repositories{
    maven ("<https://dl.bintray.com/korlibs/korlibs>")
    google()
    jcenter()
    mavenLocal()
    mavenCentral()
    maven("<https://oss.sonatype.org/content/repositories/snapshots>")
    maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
    maven {
        url = uri("<https://repo.repsy.io/mvn/chrynan/public>")
    }
}


kotlin {
    android()
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    cocoapods {
        version = "1.0.1"
        summary = "Common Module"
        homepage = "No link"
        ios.deploymentTarget = "12.1"
        podfile = project.file("../iosApp/Podfile")
        framework {
                baseName = "commonModule"
                isStatic = true
            }
        extraSpecAttributes["resources"] = "['src/commonMain/resources/**', 'src/iosMain/resources/**']"
    }


    // Block from <https://github.com/cashapp/sqldelight/issues/2044#issuecomment-721299517>.
    val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("com.squareup.sqldelight:runtime:1.5.5")
                implementation("com.squareup.sqldelight:coroutines-extensions:1.5.5")
                implementation("io.ktor:ktor-client-core:2.3.2")
                implementation("io.ktor:ktor-client-logging:2.3.2")
                implementation("io.ktor:ktor-client-content-negotiation:2.3.2")
                implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.2")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
                implementation("commons-codec:commons-codec:1.15")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1")
                implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
                api("dev.icerock.moko:mvvm-core:0.12.0") // only ViewModel, EventsDispatcher, Dispatchers.UI
                api("dev.icerock.moko:mvvm-livedata:0.12.0") // api mvvm-core, LiveData and extensions
                api("dev.icerock.moko:mvvm-state:0.12.0") // api mvvm-livedata, ResourceState class and extensions
                api("dev.icerock.moko:mvvm-livedata-resources:0.12.0") // api mvvm-core, moko-resources, extensions for LiveData with moko-resources
                implementation(compose.ui)
                implementation(compose.foundation)
                implementation(compose.material)
                @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
                implementation(compose.components.resources)
                implementation("com.chrynan.navigation:navigation-core:0.9.0")
                implementation("com.chrynan.navigation:navigation-compose:0.9.0")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation( "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
                implementation("io.ktor:ktor-client-android:2.3.2")
                implementation("com.squareup.sqldelight:android-driver:1.5.5")
                api("dev.icerock.moko:mvvm-livedata-material:0.12.0") // api mvvm-livedata, Material library android extensions
                api("dev.icerock.moko:mvvm-livedata-glide:0.12.0") // api mvvm-livedata, Glide library android extensions
                api("dev.icerock.moko:mvvm-livedata-swiperefresh:0.12.0") // api mvvm-livedata, SwipeRefreshLayout library android extensions
                api("dev.icerock.moko:mvvm-databinding:0.12.0") // api mvvm-livedata, DataBinding support for Android
                api("dev.icerock.moko:mvvm-viewbinding:0.12.0") // api mvvm-livedata, ViewBinding support for Android
                api("androidx.activity:activity-compose:1.6.1")
                api("androidx.appcompat:appcompat:1.6.1")
                api("androidx.core:core-ktx:1.9.0")
            }
        }
//        val androidTest by getting {
//            dependencies {
//                implementation(kotlin("test-junit"))
//                implementation("junit:junit:4.13.2")
//            }
//        }

        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)
            dependencies {
                //implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.3.5")
                implementation("io.ktor:ktor-client-darwin:2.3.2")
                implementation("com.squareup.sqldelight:native-driver:1.5.5")

            }
        }
            val iosTest by getting
    }
    // export correct artifact to use all classes of library directly from Swift
    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.12.0")
            export("dev.icerock.moko:mvvm-livedata:0.12.0")
            export("dev.icerock.moko:mvvm-livedata-resources:0.12.0")
            export("dev.icerock.moko:mvvm-state:0.12.0")
        }
    }
}

android {
    compileSdkVersion(33)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    sourceSets["main"].resources.srcDirs("src/commonMain/resources")
    defaultConfig {
        minSdkVersion(24)
        targetSdkVersion(33)
    }
    buildToolsVersion = "31.0.0"
}

sqldelight {
    database("WowDatabase") {
        packageName = "db"
        version = 6
    }
}

compose {
    kotlinCompilerPlugin.set("1.4.5")
    kotlinCompilerPluginArgs.add("suppressKotlinVersionCompatibilityCheck=1.9.0")
}

//val packForXcode by tasks.creating(Sync::class) {
//    group = "build"
//    val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
//    val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
//    val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
//    val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
//    inputs.property("mode", mode)
//    dependsOn(framework.linkTask)
//    val targetDir = File(buildDir, "xcode-frameworks")
//    from({ framework.outputDirectory })
//    into(targetDir)
//}

//tasks.getByName("build").dependsOn(packForXcode)
a
I’d try removing this block, it makes your source-set hierarchy behave in a very strange way :
Copy code
val onPhone = System.getenv("SDK_NAME")?.startsWith("iphoneos") ?: false
    if (onPhone) {
        iosArm64("ios")
    } else {
        iosX64("ios")
    }
v
This helped, but the error transformed into FAILURE: Build failed with an exception. * What went wrong: Task ‘packForXCode’ not found in project ‘:commonModule’.