I’m developing a Compose Multiplatform, where I need to access packageName/bundleId from android and apple(ios and macOs) platform.
build.gralde.kts (composeApp)
kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "${JavaVersion.VERSION_1_8}"
freeCompilerArgs += "-Xjdk-release=${JavaVersion.VERSION_1_8}"
}
}
}
jvm()
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
}
listOf(
macosX64(),
macosArm64(),
).forEach {
it.binaries.framework {
baseName = "ComposeApp"
isStatic = true
}
}
sourceSets {
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
}
androidMain.dependencies {
implementation(compose.uiTooling)
implementation(libs.androidx.activityCompose)
}
val jvmMain by getting {
dependsOn(macosMain.get())
dependencies {
implementation(compose.desktop.currentOs)
}
}
}
}
commonMain
expect val bundleId: String
androidMain
actual val bundleId: String
get() = packageInfo.applicationInfo?.loadLabel(packageManager)?.toString().orEmpty()
iosMain
actual val bundleId: String
get() = NSBundle.mainBundle.bundleIdentifier.orEmpty()
macosMain
actual val bundleId: String
get() = NSBundle.mainBundle.bundleIdentifier.orEmpty() //
In macosMain
sourcet I’m not able to access macos specific API’s, if I make jvmMain
depends on macosMain
sourceSet.
Note : As I’ll not able to access macOs properties inside jvmMain so I’ve marked jvmMain depends on macosMain sourceSet, and add implementation inside macosMain.
If I remove depends on line from jvmMain sourceSet then I I’m able to access macos platform API’s inside macosMain sourceSet.