touchlab / KMMBridge

KMMBridge is a set of Gradle tooling that facilitates publishing and consuming pre-built KMM (Kotlin Multiplatform Mobile) Xcode Framework binaries. See https://kmmbridge.touchlab.co/docs to get started.
https://kmmbridge.touchlab.co/
Apache License 2.0
339 stars 20 forks source link

No 'swiftinterface' files found within .../moduleName.framework/Modules/moduleName.swiftmodule #247

Closed pkliang closed 1 week ago

pkliang commented 3 weeks ago

Summary

I am integrating KMMBridge version 0.5.5 and Skie into a KMP project, but it always fails with the following gradle task in GitHub action and my local machine.

./gradlew :moduleName:assembleModuleNameReleaseXCFramework 

No 'swiftinterface' files found within .../moduleName.framework/Modules/moduleName.swiftmodule

Without kmmbridge plugin, everything works fine. swiftinterface files are generated as expected and the assembleReleaseXCFramework task is executed succefully.

Details

Here is my kts file

plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.kotlin.serialization)
    alias(libs.plugins.skie)
    alias(libs.plugins.android.library)
    alias(libs.plugins.kmmbridge)
    `maven-publish`
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
    androidTarget {
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_17)
        }
        publishLibraryVariants("release", "debug")
    }

    jvm {
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_17)
        }
    }

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
           // baseName = xcframeworkName
            // Specify CFBundleIdentifier to uniquely identify the framework
            binaryOption("bundleId", "nmt.apps.kmp.${xcframeworkName}")
            //xcf.add(this)
            isStatic = true
        }
    }

    sourceSets {

        androidMain.dependencies {
            implementation(libs.ktor.client.okhttp.eap)
            implementation(libs.kotlinx.coroutines.android)
        }
        commonMain.dependencies {
            implementation(libs.ktor.client.core.eap)
            implementation(libs.ktor.client.logging.eap)
            implementation(libs.ktor.client.content.negotiation.eap)
            implementation(libs.ktor.serialization.json.eap)

            implementation(libs.logback.classic)
            implementation(libs.kotlinx.serialization.json)

            implementation(libs.coroutines.core)
        }
        iosMain.dependencies {
            implementation(libs.ktor.client.darwin.eap)
        }
        jvmMain.dependencies {
            implementation(libs.ktor.client.okhttp.eap)
        }
    }
}

android {
    namespace = "nmt.apps.kmp.kai"
    compileSdk = libs.versions.compileSdk.get().toInt()

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

    defaultConfig {
        minSdk = libs.versions.minSdk.get().toInt()
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}

addGithubPackagesRepository()

kmmbridge {
    mavenPublishArtifacts()
    spm()
}
TadeasKriz commented 3 weeks ago

Hi @pkliang, which version of SKIE and Kotlin are you using?

ferinagy commented 3 weeks ago

Hi, not the OP, but we also ran into this issue with our project the versions used are:

kmmbridge = "0.5.5"
skie = "0.8.2"
ferinagy commented 3 weeks ago

After a little further detective work, it worked with SKIE 0.6.4, but breaks with 0.7.0.

TadeasKriz commented 3 weeks ago

Since SKIE 0.7.0 we don't enable library evolution by default to reduce compilation time. It does get automatically enabled when building XCFrameworks, but it's possible KMMBridge breaks that. We'll look into it.

In the meantime, you can use SKIE 0.8.2 and enable library evolution explicitly:

skie {
    build {
        enableSwiftLibraryEvolution.set(true)
    }
}
pkliang commented 1 week ago

Since SKIE 0.7.0 we don't enable library evolution by default to reduce compilation time. It does get automatically enabled when building XCFrameworks, but it's possible KMMBridge breaks that. We'll look into it.

In the meantime, you can use SKIE 0.8.2 and enable library evolution explicitly:

skie {
    build {
        enableSwiftLibraryEvolution.set(true)
    }
}

Thanks, this fixes the issue.