Android 使用JFrog Artifactory的Kotlin多平台库

Android 使用JFrog Artifactory的Kotlin多平台库,android,maven,kotlin,gradle,kotlin-multiplatform,Android,Maven,Kotlin,Gradle,Kotlin Multiplatform,我将一个共享模块从Kotlin多平台上传到JFrogs Artifactory。目标是在另一个android应用程序项目中使用此共享模块,并在项目之间共享业务逻辑 我试着只上传共享模块的android变体——就目前而言,iOS变体不需要上传到artifactory 我在Kotlin多平台项目中共享模块的build.gradle.kts中编写了以下代码: plugins { kotlin("multiplatform") id("com.android

我将一个共享模块从Kotlin多平台上传到JFrogs Artifactory。目标是在另一个android应用程序项目中使用此共享模块,并在项目之间共享业务逻辑

我试着只上传共享模块的android变体——就目前而言,iOS变体不需要上传到artifactory

我在Kotlin多平台项目中共享模块的build.gradle.kts中编写了以下代码:

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("kotlin-android-extensions")
    kotlin("plugin.serialization")

    // plugins required for uploading to artifactory
    id("maven-publish")
    id("com.jfrog.artifactory") version "4.13.0"
}

.
.
.

artifactory {
    setContextUrl("https://rbartifactory.jfrog.io/artifactory/")
    publish(delegateClosureOf<PublisherConfig> {
        repository(delegateClosureOf<DoubleDelegateWrapper> {
            setProperty("repoKey", "App-Shared-Test-KMP")
            setProperty("username", "<MY-USERNAME>")
            setProperty("password", "<MY-USER-API-KEY>")
            setProperty("maven", true)
        })
        defaults(delegateClosureOf<groovy.lang.GroovyObject> {
            invokeMethod("publications", arrayOf(
                    "androidDebug", "androidRelease", "kotlinMultiplatform", "metadata"
            ))
        })
    })
}

在android应用程序中,我在此处运行此错误:

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.
为什么在尝试使用该库时会出现此错误?我如何在其他android应用程序中使用jfrogs artifactory的Kotlin多平台库

这可能是因为通过运行./gradlew artifactoryPublish上传的JAR?是否应该在artifactory中上载aar文件

也许这句话不再管用了?我读到的文章是在2020年5月写的,从那以后,Kotlin发布了一些主要的多平台版本:

defaults(delegateClosureOf<groovy.lang.GroovyObject> {
            invokeMethod("publications", arrayOf(
                    "androidDebug", "androidRelease", "kotlinMultiplatform", "metadata"
            ))
        })
我想我需要在其中添加一些其他属性,而不是androidDebug和androidRelease


我真的非常感谢在这方面的每一个帮助-我正在寻找一个解决方案。

对于android应用程序,aar库是必要的-所以我需要将air文件上传到artifactory

要上载aar文件,我将发布块添加到KMP项目中共享模块的build.gradle.kts中:

publishing {
    publications {
        create<MavenPublication>("aar") {
            artifact("$buildDir/outputs/aar/${project.name}-release.aar")
        }
    }
}
在这些更改之后,我清理项目并构建所有工件:

./gradlew clean
./gradlew :shared:build
当所有资产构建成功且aar文件位于KMP项目的outputs文件夹中时,我使用./gradlew artifactoryPublish上传aar的成功,然后我可以在另一个android应用程序中简单地使用它们


Vadim对这个问题的回答帮助我编写了将aar上传到artifactory的代码。

对于android应用程序,aar库是必要的-因此我需要将air文件上传到artifactory

要上载aar文件,我将发布块添加到KMP项目中共享模块的build.gradle.kts中:

publishing {
    publications {
        create<MavenPublication>("aar") {
            artifact("$buildDir/outputs/aar/${project.name}-release.aar")
        }
    }
}
在这些更改之后,我清理项目并构建所有工件:

./gradlew clean
./gradlew :shared:build
当所有资产构建成功且aar文件位于KMP项目的outputs文件夹中时,我使用./gradlew artifactoryPublish上传aar的成功,然后我可以在另一个android应用程序中简单地使用它们


瓦迪姆对这个问题的回答帮助我编写了将aar上传到artifactory的代码。

谢谢你的回答。我注意到的另一件事是:这个版本的插件工作得很好:classpathrg.jfrog.buildinfo:buildinfo提取器gradle:4.13.0我用最新版本4.15.2尝试过,但它只是间歇性工作。谢谢你的回答。我注意到的另一件事是,这个版本的插件工作得很好:classpathrg.jfrog.buildinfo:buildinfo提取器gradle:4.13.0我用最新版本4.15.2尝试过,它只是间歇性地工作。