Wasn’t sure whether to post this here or in <#C19F...
# multiplatform
k
Wasn’t sure whether to post this here or in #gradle but I am trying to create a KMP library using
com.vanniktech.maven.publish
, and I am running into errors when importing the library into a project. Publishing works fine, but once I add it to a project I get this error:
Copy code
Execution failed for task ':sample:android:dataBindingMergeDependencyArtifactsDebug'.
> Could not resolve all files for configuration ':sample:android:debugRuntimeClasspath'.
   > Could not resolve io.github.kevinschildhorn:atomik:0.0.3.
     Required by:
         project :sample:android > project :sample:common
      > No matching variant of io.github.kevinschildhorn:atomik:0.0.3 was found. The consumer was configured to find a component for use during runtime, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.0.2', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - Variant 'iosArm64ApiElements-published' capability io.github.kevinschildhorn:atomik:0.0.3:
              - Incompatible because this component declares a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' and the consumer needed a component for use during runtime, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
              - Other compatible attributes:
                  - Doesn't say anything about com.android.build.api.attributes.AgpVersionAttr (required '8.0.2')
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
                  - Doesn't say anything about its target Java environment (preferred optimized for Android)
I saw a post about this being an issue in an earlier version and it suggested only doing a release version, but if I do that then I get some
Unresolved Reference
errors when building, even though importing works fine in code. Using:
Copy code
classpath("com.android.tools.build:gradle:8.0.2")
classpath(kotlin("gradle-plugin", "1.8.10"))

distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
1
c
Does you KMP library declare the Android target?
k
yes
Copy code
kotlin {
    explicitApi()
    android()
    ...
}
j
You need to explicitly declare Android variants for publication:
Copy code
kotlin {
    android {
        publishAllLibraryVariants() // or
        publishLibraryVariants("debug", "release")
    }
    ...
}
k
Thanks! I’ll give that a shot
that worked thank you!