Hi. Published Kotlin Multiplatform Android library...
# multiplatform
r
Hi. Published Kotlin Multiplatform Android library on local maven but when importing library into an app as dependency getting error:
Copy code
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve xx.yy.mpp:kommon-android:0.0.1.
     Required by:
         project :app
      > No matching variant of xx.yy.mpp:kommon-android:0.0.1 was found. The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - Variant 'android-releaseApiElements' capability xx.yy.mpp:kommon-android:0.0.1 declares an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
          - Variant 'android-releaseRuntimeElements' capability xx.yy.mpp:kommon-android:0.0.1 declares a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
              - Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
          - Variant 'metadata-api' capability xx.yy.mpp:kommon-android:0.0.1:
              - Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
              - Other compatible attribute:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
          - Variant 'metadata-commonMainMetadataElements' capability xx.yy.mpp:kommon-android:0.0.1:
              - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed an API of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
              - Other compatible attribute:
                  - Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
Feeling it is more
maven-publish
plugin issue but since it is KMP project I thought somebody else has faced with the same issue.
b
What command did you execute to publish this and what platforms is it targeting?
r
Used
publishToMavenLocal
gradle task. Target platform:
Copy code
kotlin {
    android {
        publishAllLibraryVariants()
    }

    ios {
        binaries {
            framework {
                baseName = "XXX"
            }
        }
    }
...
b
I literally just came here to address the same issue. From what I’ve been looking through, the Plugin does not properly recognize any variants set by the android block. The actual aar is built through the assemble directive and it default output to
build/outputs/aar
but no publishable is generated, I am working on generating a manual publish, but am concerned I will not properly tie in with the metadata generated for publishing This seems to be an issue with Kotlin 1.4, and 1.4.10, as the project I am working on works great on the previous versions before 1.4, and is not working as expected on upgrade.
Given that “release” and “debug” are default variants on an android build, I have even tried to use the
publishLibraryVariants = listOf("release", "debug")
which errors out with the snippet.
r
@Benjamin Charais I had the issue before. Have you tried to declare
id("com.android.library")
before multiplatform plugin declaration? Also, do get the same error when you try to build Android app with dependency of published multiplatform library on local maven?
b
Yes we are absolutely using the
com.android.library
for our android declaration. I do get the same error you described.
r
@Benjamin Charais a workaround which worked for me is state
matchingFallbacks
versions in your app’s build script. If your app is including Multiplatform release version, then it should look like this.
Copy code
android {
    buildTypes {
        debug {
            matchingFallbacks = ['release']
        }
    }
}
b
That would normally work, but the publish itself does not actually publish anything anymore — the android itself is not published, and it cmes back to the variants themselves not being detected by the Kotlin Multiplatform Build
r
Can you show a list of plugins you're using in your multiplatform project?
Just because you mentioned that you're getting other kind of error which I experienced as well and got fixed. If so, you'll find an answer in this thread https://kotlinlang.slack.com/archives/C3PQML5NU/p1597887361394800
b
Wow, I’m going to try that now… If that fixes this, I super appreciate it, and wish it was much more clearly laid out in the documentation
Oddly, this has never been an issue prior to upgrading to 1.4, so that made it even worse. And yes, this does fix the issue. As for your issue, if you arent using flavors, the flag
publishLibraryVariantsGroupedByFlavor = true
might be helpful
r
I thought so it will be helpful. Glad you posted the error output. I recognised it instantly because been in that rabbit hole for days. Thanks. Will try it.
b
Thank you for the help, this has been a big blocker for my team to move to 1.4, and we depend on a lot of multiplatform builds so this is huge.
r
Your suggested change worked for me. Better than changing clients build script. Thank you too.