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 followingbuild.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
- Verified that the :library module has debug and release variants by running ./gradlew :library:outgoingVariants.
- Ensured that both app and library modules use the same Android Gradle Plugin (AGP) version (8.5.2).
- Confirmed jvmTarget compatibility across both modules (JVM_11).
- 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.