https://kotlinlang.org logo
r

rb90

12/23/2020, 3:59 PM
Hi all, I am a Kotlin beginner and I decided to play a little bit around with Kotlin Multiplatform. I am looking for a way to version a shared module - so I started think about using jfrog artifactory for that purpose. Did anyone of you already upload a Kotlin Multiplatform shared module to artifactory an consume it from there?
1
Copy code
Could not determine the dependencies of task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
   > Could not resolve com.rb.kmp_test_shared_lib:shared:1.0.4.
     Required by:
         project :app
      > No matching variant of com.rb.kmp_test_shared_lib:shared:1.0.4 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 'commonMainMetadataElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
              - 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')
          - Variant 'iosArm64ApiElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
              - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' 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 'iosArm64MetadataElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
              - Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' 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 'iosX64ApiElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
              - Incompatible because this component declares a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' 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 'iosX64MetadataElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
              - Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native' 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 'metadataApiElements-published' capability com.rb.kmp_test_shared_lib:shared:1.0.4:
              - 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')
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
I was able to upload the package successfully to artifactory. But when I try to consume it from there in another android app I get this error here:
r

rb90

12/23/2020, 4:11 PM
Hi Kris - nice to meet you and wow you are my hero! I read that article. This was my entry point and I guess the reason why I am able to upload to artifactory 👍. But the part where I try to consume did not work for me. I run in the error I posted above 😞
k

Kris Wong

12/23/2020, 4:12 PM
and you have the bit about
publishAllLibraryVariants
?
r

rb90

12/23/2020, 4:13 PM
Yes 😕:
Copy code
kotlin {
.
.
.
    android() {
        publishAllLibraryVariants()
    }
}
I am so desperate I already wrote a stackoverflow question here with some more details 😞: https://stackoverflow.com/questions/65407017/use-kotlin-multiplatform-library-from-jfrog-artifactory
k

Kris Wong

12/23/2020, 4:16 PM
what version of gradle are you using?
why does the screenshot show a jar and not an android aar?
you're also consuming a jar
r

rb90

12/23/2020, 4:20 PM
Ah okay so already when uploading there went sth wrong? an aar should be uploaded to artifactory right?
I am sorry I am a really new here with kotlin, artifactory and kotlin multiplatform 😁.
when running
./gradlew --version
in the kmp project it says that I am using Gradle 6.7
It seems that with the setup made jars will be generated not aar files? What can I do to force the generation and upload of aar files?
k

Kris Wong

12/23/2020, 4:32 PM
if you have an android target, then it should be publishing android artifacts
r

rb90

12/23/2020, 4:47 PM
I put all the code for building the artifacts in the build file of the shared module of the kotlin multiplatform project. Where do I need to define that those artifacts should be build for an android target?
I guess the problem is somewhere in this lines here:
Copy code
defaults(delegateClosureOf<groovy.lang.GroovyObject> {
            invokeMethod("publications", arrayOf(
                    "androidDebug", "androidRelease", "kotlinMultiplatform", "metadata"
            ))
        })
The article was written in May 2020, since then there were some kotlin releases. I guess
androidDebug
and
androidRelease
should be changed to sth. else. Kris did the implementation you described in the tutorial still work for you?
Solved my problem and also updated my stackoverflow question. Thanks for the hint with the aar's - this finally did the trick 😉. @Kris Wong maybe you also want to please update your medium article? I guess it won't work anymore like you described it there because of further KMP releases?
5 Views