Every year or so I take a stab at bringing KMP int...
# multiplatform
t
Every year or so I take a stab at bringing KMP into our existing application at work and every year I get so bogged down with just getting things to build that I give up. This time I was able to get the shared module setup and dependencies added for ktor and implementation done to hit our apis but then when I went to build it all went down hill. The android app is failing to build. If I remove
implementation (project(":shared"))
then the android app builds just fine. Error message is this:
Copy code
Could not determine the dependencies of task ':udisc:compileFreeInternalTestDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':udisc:freeInternalTestDebugCompileClasspath'.
   > Could not resolve project :shared.
     Required by:
         project :udisc
      > No matching variant of project :shared 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.0', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'internalTestDebug', attribute 'com.android.build.api.attributes.ProductFlavor:versionCode' with value 'free', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
Any suggestions?
m
Can you post the full error?
Looks like
shared
is missing
androidTarget()
or using other settings but it’s hard to tell
t
this is my shared build file
Copy code
plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.android.library)
//    alias(libs.plugins.kotlin.serialization)
}

kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "17"
            }
        }
    }

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
            isStatic = true
        }
    }

    sourceSets {
        commonMain.dependencies {
//            implementation(libs.ktor.client.core)
//            implementation(libs.ktor.serialization)
//            implementation(libs.kotlinx.coroutines.core)
//            implementation(libs.kotlinx.datetime)
        }
        androidMain.dependencies {
//            implementation(libs.ktor.client.okhttp)
//            implementation(libs.ktor.negotiation)
//            implementation(libs.ktor.json)
//            implementation(libs.okhttp.logging)
        }
        iosMain.dependencies {
//            implementation(libs.ktor.client.darwin)
        }
    }
}

android {
    namespace = "com.udisc.shared"
    compileSdk = 34
    defaultConfig {
        minSdk = 28
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}
full error
m
Copy code
Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'internalTestDebug'
That’s probably it
You should be able to solve it using matchin fallbacks: https://developer.android.com/build/build-variants#resolve_matching_errors
t
Yes! This worked, thank you!!