<@U0B9PKJ7K> You’ve mentioned in a couple spots (e...
# multiplatform
r
@h0tk3y You’ve mentioned in a couple spots (eg https://youtrack.jetbrains.com/issue/KT-27535#focus=streamItem-27-3199028-0-0) that it’s possible to use
digital.wup.android-maven-publish
to publish the android part of a
kotlin-multiplatform
project. It’s not clear to me how that can be consumed by another
kotlin-multiplatform
project. Is there a sample of that anywhere?
My best-guess minimal config for this is at https://github.com/russhwolf/AndroidLibDemo. See in particular library publishing config at https://github.com/russhwolf/AndroidLibDemo/blob/master/build.gradle and app consuming config at https://github.com/russhwolf/AndroidLibDemo/blob/master/app/app/build.gradle. This fails with
Copy code
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not resolve com.example:AndroidLibraryDemo-android:0.0.1.
  Required by:
      project :app
   > Unable to find a matching configuration of com.example:AndroidLibraryDemo-android:0.0.1: Configuration 'metadata-api':
       - Found artifactType 'jar' but wasn't required.
       - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
       - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
       - Found org.gradle.status 'release' but wasn't required.
       - Required org.gradle.usage 'java-api' and found incompatible value 'kotlin-api'.
       - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'common'.
> Could not resolve com.example:AndroidLibraryDemo:0.0.1.
  Required by:
      project :app
   > Unable to find a matching configuration of com.example:AndroidLibraryDemo:0.0.1:
       - Configuration 'ios-api':
           - Found artifactType 'org.jetbrains.kotlin.klib' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-api' and found incompatible value 'kotlin-api'.
           - Found org.jetbrains.kotlin.native.target 'ios_x64' but wasn't required.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'native'.
       - Configuration 'js-api':
           - Found artifactType 'jar' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-api' and found incompatible value 'kotlin-api'.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'js'.
       - Configuration 'js-runtime':
           - Found artifactType 'jar' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-api' and found incompatible value 'kotlin-runtime'.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'js'.
       - Configuration 'metadata-api':
           - Found artifactType 'jar' but wasn't required.
           - Required com.android.build.api.attributes.BuildTypeAttr 'debug' but no value provided.
           - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but no value provided.
           - Found org.gradle.status 'release' but wasn't required.
           - Required org.gradle.usage 'java-api' and found incompatible value 'kotlin-api'.
           - Required org.jetbrains.kotlin.platform.type 'androidJvm' and found incompatible value 'common'.
I guess I can be more explicit (in response to a question that disappeared). Publishing works for me, in that I can see the aar saved to
~/.m2/repository/...
, but I don't understand how to reference it from the consuming module (eg an app which is using the library)
d
It took me a while and a bunch of hacks to get android publishing working and i’m not sure if I saw your issue or not. One thing I had to do was use a different artifact name entirely for the custom android aar artifact (I appended
-patched
here: https://github.com/russhwolf/AndroidLibDemo/blob/50471065089ce70c31e9c4b006f1d3925d491769/build.gradle#L93), this may solve your issue. When you publish both the original android artifact and the custom one will be published. Consuming the custom artifact should work so far as that the library can be pulled.
Copy code
publications {
    // Patch for MPP Android publishing
    // <https://youtrack.jetbrains.com/issue/KT-27535>
    // <https://kotlinlang.slack.com/archives/C3PQML5NU/p1543936551055500?thread_ts=1543861394.034600&cid=C3PQML5NU>
    if (includeAndroid) {
      mavenAar(MavenPublication) {
        artifactId = project.name + '-android-patched'
        from components.android
        artifact("$buildDir/outputs/aar/${project.name}-release.aar")
        artifacts.removeAll(artifacts.matching { !it.file.name.endsWith('aar') })
        pom.withXml {
          def dependenciesNode = asNode().appendNode('dependencies')
          configurations.implementation.allDependencies.each {
            def dependencyNode = dependenciesNode.appendNode('dependency')
            dependencyNode.appendNode('groupId', it.group)
            dependencyNode.appendNode('artifactId', it.name)
            dependencyNode.appendNode('version', it.version)
            dependencyNode.appendNode('scope', 'compile')
          }
        }
      }
    }
}
This configuration works for our internal libraries.
r
Oh interesting. So you used
-android-patched
rather than just
-android
. It's strange to me that that would matter but I definitely don't have a deep understanding of this stuff. I'll give it a try when I get a chance.
d
Right, I assume some metadata from the mpp plugin is overriding the correct info from the android publishing plugin. But i’m also not sure 🤷‍♂️
j
I was able to publish and consume using this:
Copy code
apply plugin: 'digital.wup.android-maven-publish'

task androidSourceJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier "sources"
}

publishing {
    publications {
        mavenAar(MavenPublication) {
            artifactId = project.name + "-android"
            from components.android
            artifacts.removeAll { it.file.name.endsWith('jar') }
            artifact androidSourceJar
        }
    }
}
Copy code
api 'com.lightningkite:koolui-android:0.0.2'
d
Interesting @josephivie, I’ve been unable to get the simple configuration to include/upload the aar artifact and include dependencies in the pom. Did you make any special configuration changes on the android plugin itself to get that working?
j
Probably should have written that I’m also using
apply plugin: 'digital.wup.android-maven-publish'
d
Same, I started with the original note from @h0tk3y regarding the android publication issue. Wasn’t quite as strait forward in my project for some reason.
j
No, I’m not doing anything special besides that. That’s where I started from too. I’m consuming it successfully too.
I did have to make a couple of changes to the little script he wrote, as I got a concurrency issue
d
👍 Good to know, must be something about my project then. Thank you.