https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

Jeff Tycz

05/23/2021, 1:06 AM
When I publish my KMM library to Maven and try to add my dependency to an Android application it seems I have to declare it like this for it to work
Copy code
releaseImplementation 'io.github.tyczj:myLib-android:0.X.X@aar'
debugImplementation 'io.github.tyczj:myLib-android-debug:0.X.X@aar'
What do I have to do to be able to add the dependency like one would for basically every other KMM or Android library? like this is what I am looking for
Copy code
implementation 'io.github.tyczj:myLib-android:0.X.X
r

russhwolf

05/23/2021, 3:03 AM
Hard to say without seeing your gradle config. You should get it the way you want by default when you apply the
maven-publish
plugin. Docs here if it helps https://kotlinlang.org/docs/mpp-publish-lib.html#publish-an-android-library
j

Jeff Tycz

05/23/2021, 12:08 PM
@russhwolf here is the project, its just a simple logging library. I believe I followed everything that link says to do
r

russhwolf

05/23/2021, 1:16 PM
Hmm. Maybe your staging build type is causing an issue. But I'm not sure since you don't publish it. If you add
matchingFallbacks = listOf("release", "debug")
to your consuming app, does it help?
j

Jeff Tycz

05/23/2021, 1:36 PM
Fall backs don't help. And the library is published
r

russhwolf

05/23/2021, 1:36 PM
I mean the staging build type isn't published
But maybe having it there still impacts how it gets consumed
Not totally sure but that was the most nonstandard thing that jumped out at me compared to the default library config
j

Jeff Tycz

05/23/2021, 1:42 PM
how would I publish the staging build type? I just assumed everything was handled already with that
r

russhwolf

05/23/2021, 1:43 PM
j

Jeff Tycz

05/23/2021, 1:49 PM
so it would look like this?
Copy code
publishLibraryVariants("release", "debug", "staging")
r

russhwolf

05/23/2021, 1:49 PM
yeah give that a try
alternatively you could drop the staging build type from the library
j

Jeff Tycz

05/23/2021, 2:26 PM
when I remove the staging i get a warning after a gradle sync saying
Failed to resolve: Lumberjack-android-1.0.2-samplessources
When I do a build I get this gradle error
Copy code
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve io.github.tyczj.lumberjack:Lumberjack-android:1.0.2.
     Required by:
         project :app
      > No matching variant of io.github.tyczj.lumberjack:Lumberjack-android:1.0.2 was found. The consumer was configured to find a runtime 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 'commonMainMetadataElements-published' capability io.github.tyczj.lumberjack:Lumberjack-android:1.0.2:
              - 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 a runtime 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 'metadataApiElements-published' capability io.github.tyczj.lumberjack:Lumberjack-android:1.0.2:
              - 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 a runtime 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 'releaseApiElements-published' capability io.github.tyczj.lumberjack:Lumberjack-android:1.0.2 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
              - Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
          - Variant 'releaseRuntimeElements-published' capability io.github.tyczj.lumberjack:Lumberjack-android:1.0.2 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'
2 Views