尝试将 moko 资源依赖项添加到我的 compose 多平台项目时出现以下错误
Resolving dependency configuration 'metadataCompilationApi' is not allowed as it is defined as 'canBeResolved=false'. Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'metadataCompilationApi' should be resolved.
这是我的build.gradle.kts
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.metadataDescriptor
import org.jetbrains.kotlin.gradle.plugin.sources.dependsOnClosure
import org.jetbrains.kotlin.gradle.tasks.DummyFrameworkTask
plugins {
alias(libs.plugins.multiplatform)
alias(libs.plugins.compose)
alias(libs.plugins.android.application)
alias(libs.plugins.buildConfig)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.sqlDelight)
id("dev.icerock.mobile.multiplatform-resources")
}
kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "ComposeApp"
isStatic = true
export("dev.icerock.moko:resources:0.22.3")
export("dev.icerock.moko:graphics:0.9.0")
}
}
sourceSets {
all {
languageSettings {
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
}
}
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
@OptIn(ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation(libs.voyager.navigator)
implementation(libs.voyager.screen.model)
implementation(libs.voyager.livedata)
implementation(libs.voyager.bottomSheet.navigator)
// Screen Model
// implementation(libs.composeImageLoader)
implementation(libs.napier)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.moko.mvvm)
implementation(libs.ktor.core)
implementation(libs.kotlinx.serialization.json)
implementation(libs.multiplatformSettings)
}
}
commonTest.dependencies {
implementation(kotlin("test"))
}
val androidMain by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.activityCompose)
implementation(libs.compose.uitooling)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.ktor.client.okhttp)
implementation(libs.sqlDelight.driver.android)
}
}
val iosArm64Main by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.ktor.client.darwin)
implementation(libs.sqlDelight.driver.native)
}
}
val iosArm64Test by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.ktor.client.darwin)
implementation(libs.sqlDelight.driver.native)
}
}
val iosX64Main by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.ktor.client.darwin)
implementation(libs.sqlDelight.driver.native)
}
}
val iosSimulatorArm64Main by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.ktor.client.darwin)
implementation(libs.sqlDelight.driver.native)
}
}
}
}
android {
namespace = "irancell.nwg.wfm"
compileSdk = 34
defaultConfig {
minSdk = 24
targetSdk = 34
applicationId = "irancell.nwg.wfm.androidApp"
versionCode = 1
versionName = "1.0.0"
}
sourceSets["main"].apply {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/resources")
resources.srcDirs("src/commonMain/resources")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.4"
}
}
sqldelight {
databases {
create("MyDatabase") {
// Database configuration here.
// https://cashapp.github.io/sqldelight
packageName.set("irancell.nwg.wfm.db")
}
}
}
dependencies {
commonMainApi(libs.bundles.moko.resources)
}
multiplatformResources {
multiplatformResourcesPackage = "irancell.nwg.wfm"
}
和我的 composeApp 模块的 build.gradle.kts :
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.kotlin.gradle.internal.kapt.incremental.metadataDescriptor
import org.jetbrains.kotlin.gradle.plugin.sources.dependsOnClosure
import org.jetbrains.kotlin.gradle.tasks.DummyFrameworkTask
plugins {
alias(libs.plugins.multiplatform)
alias(libs.plugins.compose)
alias(libs.plugins.android.application)
alias(libs.plugins.buildConfig)
alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.sqlDelight)
id("dev.icerock.mobile.multiplatform-resources")
}
kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "ComposeApp"
isStatic = true
export("dev.icerock.moko:resources:0.22.3")
export("dev.icerock.moko:graphics:0.9.0")
}
}
sourceSets {
all {
languageSettings {
optIn("org.jetbrains.compose.resources.ExperimentalResourceApi")
}
}
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
@OptIn(ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation(libs.voyager.navigator)
implementation(libs.voyager.screen.model)
implementation(libs.voyager.livedata)
implementation(libs.voyager.bottomSheet.navigator)
// Screen Model
// implementation(libs.composeImageLoader)
implementation(libs.napier)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.moko.mvvm)
implementation(libs.ktor.core)
implementation(libs.kotlinx.serialization.json)
implementation(libs.multiplatformSettings)
}
}
commonTest.dependencies {
implementation(kotlin("test"))
}
val androidMain by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.androidx.appcompat)
implementation(libs.androidx.activityCompose)
implementation(libs.compose.uitooling)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.ktor.client.okhttp)
implementation(libs.sqlDelight.driver.android)
}
}
val iosArm64Main by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.ktor.client.darwin)
implementation(libs.sqlDelight.driver.native)
}
}
val iosArm64Test by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.ktor.client.darwin)
implementation(libs.sqlDelight.driver.native)
}
}
val iosX64Main by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.ktor.client.darwin)
implementation(libs.sqlDelight.driver.native)
}
}
val iosSimulatorArm64Main by getting {
dependsOn(commonMain)
dependencies {
implementation(libs.ktor.client.darwin)
implementation(libs.sqlDelight.driver.native)
}
}
}
}
android {
namespace = "irancell.nwg.wfm"
compileSdk = 34
defaultConfig {
minSdk = 24
targetSdk = 34
applicationId = "irancell.nwg.wfm.androidApp"
versionCode = 1
versionName = "1.0.0"
}
sourceSets["main"].apply {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
res.srcDirs("src/androidMain/resources")
resources.srcDirs("src/commonMain/resources")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.4"
}
}
sqldelight {
databases {
create("MyDatabase") {
// Database configuration here.
// https://cashapp.github.io/sqldelight
packageName.set("irancell.nwg.wfm.db")
}
}
}
dependencies {
commonMainApi(libs.bundles.moko.resources)
}
multiplatformResources {
multiplatformResourcesPackage = "irancell.nwg.wfm"
}
和我的 libs.version.toml:
[versions]
kotlin = "1.9.21"
agp = "8.2.0"
compose = "1.5.11"
androidx-appcompat = "1.6.1"
androidx-activityCompose = "1.8.1"
compose-uitooling = "1.5.4"
voyager = "1.0.0"
composeImageLoader = "1.7.1"
napier = "2.6.1"
buildConfig = "4.1.1"
kotlinx-coroutines = "1.7.3"
moko-mvvm = "0.16.1"
ktor = "2.3.7"
kotlinx-serialization = "1.6.2"
multiplatformSettings = "1.1.1"
sqlDelight = "2.0.1"
moko-version = "0.23.0"
[libraries]
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
compose-uitooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose-uitooling" }
voyager-navigator = { module = "cafe.adriel.voyager:voyager-navigator", version.ref = "voyager" }
voyager-screen-model = { module = "cafe.adriel.voyager:voyager-screenmodel", version.ref = "voyager" }
voyager-livedata = { module = "cafe.adriel.voyager:voyager-livedata", version.ref = "voyager" }
voyager-bottomSheet_navigator = { module = "cafe.adriel.voyager:voyager-bottom-sheet-navigator", version.ref = "voyager" }
composeImageLoader = { module = "io.github.qdsfdhvh:image-loader", version.ref = "composeImageLoader" }
napier = { module = "io.github.aakira:napier", version.ref = "napier" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
moko-mvvm = { module = "dev.icerock.moko:mvvm-compose", version.ref = "moko-mvvm" }
ktor-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
multiplatformSettings = { module = "com.russhwolf:multiplatform-settings", version.ref = "multiplatformSettings" }
sqlDelight-driver-sqlite = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqlDelight" }
sqlDelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqlDelight" }
sqlDelight-driver-native = { module = "app.cash.sqldelight:native-driver", version.ref = "sqlDelight" }
sqlDelight-driver-js = { module = "app.cash.sqldelight:web-worker-driver", version.ref = "sqlDelight" }
moko-classpath = {group = "dev.icerock.moko", name = "resources-generator", version.ref = "moko-version"}
moko-resource = {group = "dev.icerock.moko", name = "resources", version.ref = "moko-version"}
moko-resource-compose = {group = "dev.icerock.moko", name = "resources-compose", version.ref = "moko-version"}
[plugins]
moko-multiplatform = {id="dev.icerock.mobile.multiplatform-resources", version.ref = "moko-version"}
multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
compose = { id = "org.jetbrains.compose", version.ref = "compose" }
android-application = { id = "com.android.application", version.ref = "agp" }
buildConfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildConfig" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
sqlDelight = { id = "app.cash.sqldelight", version.ref = "sqlDelight" }
[bundles]
moko-resources = ["moko-resource", "moko-resource-compose"]
gradle.属性:
#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
org.gradle.caching=true
org.gradle.configuration-cache=true
#Kotlin
kotlin.code.style=official
kotlin.js.compiler=ir
#Compose
org.jetbrains.compose.experimental.uikit.enabled=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
#Android
android.useAndroidX=true
android.nonTransitiveRClass=true
kotlin.native.ignoreDisabledTargets=true
#Kotlin
#MPP
kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2
#Android
android.compileSdk=34
android.targetSdk=34
android.minSdk=24
#Versions
kotlin.version=1.9.10
agp.version=8.1.1
compose.version=1.5.4
org.jetbrains.compose.experimental.macos.enabled=true
kotlin.mpp.applyDefaultHierarchyTemplate=false
settings.gradle.kts:
rootProject.name = "WFM"
include(":composeApp")
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
google()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
plugins {
val kotlinVersion = extra["kotlin.version"] as String
val agpVersion = extra["agp.version"] as String
val composeVersion = extra["compose.version"] as String
kotlin("jvm").version(kotlinVersion)
kotlin("multiplatform").version(kotlinVersion)
kotlin("android").version(kotlinVersion)
id("com.android.application").version(agpVersion)
id("com.android.library").version(agpVersion)
id("org.jetbrains.compose").version(composeVersion)
id("com.android.library") version "8.1.1"
id("org.jetbrains.kotlin.android") version "1.9.10"
}
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version("0.4.0")
}
dependencyResolutionManagement {
repositories {
mavenCentral()
google()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}
我正在尝试构建我的项目,但发生以下错误:
Resolving dependency configuration 'metadataCompilationApi' is not allowed as it is defined as 'canBeResolved=false'.
Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'metadataCompilationApi' should be resolved.
删除 gradle.properties 中的“org.gradle.configuration-cache=true”为我解决了该错误。