提问者:小点点

使用JFrog Artifactory的Kotlin多平台库


我上传了一个共享模块从静态编程语言多平台到JFrogs艺术工厂。目标是在另一个android应用程序项目中使用这个共享模块,并跨项目共享业务逻辑。

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

我在构建中编写了这段代码。格拉德尔。Kotlin多平台项目中共享模块的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"
            ))
        })
    })
}

在设置中。gradle我还添加了启用功能预览(“gradle\u元数据”)

为了实现这个gradle,我在这里读了这篇文章:https://medium.com/vmware-end-user-computing/publishing-kotlin-multiplatform-artifacts-to-artifactory-maven-a283ae5912d6

因为我希望这个共享模块在其他Android应用程序项目中使用,所以我跳过了关于iOS部分的maven发布的所有步骤。

通过成功上载到artifactory/gradlew artifactoryPublish

我尝试在android应用程序中使用它,为此,我在android应用程序构建中添加了到artifactory和此repo的连接。使用“设置我”按钮时,类似于artifactory中建议的渐变文件。最后,我还将框架链接到构建的依赖项块中。Android应用程序的渐变:

dependencies {
    .
    .
    .

    implementation(group: 'com.rb.kmp_test_shared_lib', name: 'shared', version: '1.0.4', ext: 'jar')
}

在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多平台库?

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

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

defaults(delegateClosureOf<groovy.lang.GroovyObject> {
            invokeMethod("publications", arrayOf(
                    "androidDebug", "androidRelease", "kotlinMultiplatform", "metadata"
            ))
        })

我想我需要在其中添加一些其他属性,而不是androidDebugandroidRelease

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


共1个答案

匿名用户

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

为了上传aar文件,我在构建中添加了一个publishing块。格拉德尔。KMP项目中我的共享模块的kts

publishing {
    publications {
        create<MavenPublication>("aar") {
            artifact("$buildDir/outputs/aar/${project.name}-release.aar")
        }
    }
}

我还更改了artiFactory块,并将默认值部分替换为以下内容:

defaults(delegateClosureOf<groovy.lang.GroovyObject> {
    invokeMethod("publications", "aar")
    setProperty("publishArtifacts", true)
})

在这些更改之后,我清理项目并构建所有工件:

./gradlew clean
./gradlew :shared:build

当所有资产构建成功(和aar文件在KMP项目的输出文件夹中),我上传aar的成功与./gradlew artifactoryPublish,然后我可以简单地使用它们在另一个Android应用程序。

从Vadim的问题的答案转换为gradle-kotlin-dsl J青蛙。阿蒂工厂配置帮助我编写了将aar上传到阿蒂工厂的代码。