最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gradle - Unable to Resolve Kotlin Multiplatform Library in Android Project: No Variant Found - Stack Overflow

programmeradmin3浏览0评论

I am working on a Kotlin Multiplatform project, and I am trying to use my library module (:library) in an Android application module (:app). However, I am encountering the following error during build:

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :library.
     Required by:
         project :app
      > No matching variant of project :library was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.5.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - No variants exist.

Project Structure

  • The :library module is a Kotlin Multiplatform library with the following build.gradle.kts configuration:
plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidLibrary)
    alias(libs.plugins.vanniktech.mavenPublish)
}

kotlin {
    androidTarget {
        publishLibraryVariants("release", "debug")
        compilerOptions {
            jvmTarget.set(JvmTarget.JVM_11)
        }
    }
    iosX64()
    iosArm64()
    iosSimulatorArm64()

    sourceSets {
        val commonMain by getting
        val androidMain by getting
        val iosMain by creating {
            dependsOn(commonMain)
        }
    }
}

android {
    namespace = "com.jabxm.kothless"
    compileSdk = 33
    defaultConfig {
        minSdk = 26
    }
}
  • The :app module includes the :library module as a dependency:
dependencies {
    implementation(project(":library"))
}

Environment

  • Kotlin version: 2.1.0
  • Android Gradle Plugin version: 8.5.2
  • Gradle version: 8.10.2

Question

How can I configure my Kotlin Multiplatform library so that the :app module can correctly resolve the dependency and consume the :library module? Is there a specific configuration required to expose the Android variants in a Kotlin Multiplatform project?

What I've Tried

  1. Verified that the :library module has debug and release variants by running ./gradlew :library:outgoingVariants.
  2. Ensured that both app and library modules use the same Android Gradle Plugin (AGP) version (8.5.2).
  3. Confirmed jvmTarget compatibility across both modules (JVM_11).
  4. Cleaned and rebuilt the project using ./gradlew clean build --refresh-dependencies.

Despite these efforts, I am still encountering the error, and it seems like the :library module is not exposing a default variant that the :app module can consume.

发布评论

评论列表(0)

  1. 暂无评论