Abhishek Agarwal
09/05/2023, 1:18 PMKMMbridge
to generate spm module out of my kmm library so that I can test it locally before releasing , the issue is though it generate Package.swift
file and I haved added this in my xcode project , whenever I try to import it , it says no such module found.
P.s ->my main project does not run on simulators so I tried creating a new project and added my kmm spm package and it worked for simulators but when I am compiling it for real devices it’s not working , it says no such module found
This is my gradle config 👇Abhishek Agarwal
09/05/2023, 1:18 PMkmmbridge {
// mavenPublishArtifacts()
// githubReleaseVersions()
spm()
// cocoapods("git@github.com:touchlab/PublicPodSpecs.git")
// versionPrefix.set("0.3")
//etc
}
plugins {
kotlin("multiplatform")
id("com.android.library")
id("org.jetbrains.compose")
id("co.touchlab.faktory.kmmbridge") version "0.3.7"
}
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
//targetHierarchy.default()
android {
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
isStatic = true
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.animation)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
api("moe.tlaster:precompose:1.5.0")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting {
dependencies {
api("androidx.activity:activity-compose:1.7.2")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.10.1")
implementation ("com.squareup.okhttp3:okhttp:4.11.0")
implementation ("com.squareup.okio:okio:3.2.0")
implementation ("androidx.security:security-crypto:1.1.0-alpha06")
}
}
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 {
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
namespace = "com.abhi165.noober"
compileSdk = 34
defaultConfig {
minSdk = 24
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
jvmToolchain(11)
}
}
Abhishek Agarwal
09/06/2023, 4:25 AMrusshwolf
09/06/2023, 12:38 PMAbhishek Agarwal
09/06/2023, 1:16 PMContext :
-
I am not trying to publish anything, I just want to use my KMM module in my iOS project, therefore I have only added spm()
in order to generate a spm package so that I can consume it locally in xcode.
KMM Project Structure
I am making a KMM library in which there was a single module called shared
, which I later renamed to noober
The problem: -
It generate a spm package with target name as shared
, but since in my ios project there is already a shared
spm target, so I renamed my kmm module to noober
but then also it generated spm package with shared target. I tried changing the target name in Package.swift
but it seems it not working it always import shared .
Generated Package.swift
// swift-tools-version:5.3
import PackageDescription
let packageName = "shared"
let package = Package(
name: packageName,
platforms: [
.iOS(.v13)
],
products: [
.library(
name: packageName,
targets: [packageName]
),
],
targets: [
.binaryTarget(
name: packageName,
path: "./noober/build/XCFrameworks/debug/\(packageName).xcframework"
)
,
]
)
Modified Package.swift
// swift-tools-version:5.3
import PackageDescription
let packageName = "sharedTest"
let package = Package(
name: packageName,
platforms: [
.iOS(.v13)
],
products: [
.library(
name: packageName,
targets: [packageName]
),
],
targets: [
.binaryTarget(
name: packageName,
path: "./noober/build/XCFrameworks/debug/sharedTest.xcframework"
)
,
]
)
whenever I try to import sharedTest, it says no such module foundAbhishek Agarwal
09/06/2023, 1:17 PMrusshwolf
09/06/2023, 3:10 PMit.binaries.framework("name") {}
instead of using baseName
. Doing frameworkName.set()
inside the kmmbridge block should also work, but there’s some slightly different semantics that I’m forgetting the details of.russhwolf
09/06/2023, 3:12 PM./gradlew spmDevBuild
when you make Kotlin changes so that the framework gets updated. If you previously only built one platform, that might account for the difference between device and simulator you were seeing earlier.