【问题标题】:Use maven-publish to publish Android apk and aar with build variant (Android Gradle plugin 4.0)使用 maven-publish 发布带有构建变体的 android apk 和 aar (android gradle plugin 4.0)
【发布时间】:2020-12-17 06:03:22
【问题描述】:

您好,我正在尝试关注https://developer.android.com/studio/build/maven-publish-plugin 将库 (aar) 模块和应用程序 (apk) 模块发布到 maven 存储库(maven-publish 插件)。我正在使用 kotlin gradle kts 而不是 grovy

在 grovy 中发布示例(来自上面的链接)

publishing {
    publications {
        paidRelease(MavenPublication) {
          // The following applies a component to this publication
          // which results in publishing an app bundle.
          from components.paidRelease_aab

          groupId = 'com.example.MyApp'
          artifactId = 'paid-release-aab'
          version = '1.0'
        }
        paidDebug(MavenPublication) {
          // The following applies a component to this publication
          // which results in publishing APKs in a ZIP file.
          from components.paidDebug_apk

          groupId = 'com.example.MyApp'
          artifactId = 'paid-debug-apks'
          version = '1.0'
        }
    }
}

我的 kotlin dls 发布 app 模块的代码

publications {
    create<MavenPublication>("mastercardMavenApk") {
        groupId = ProjectInfo.groupId
        artifactId = ProjectInfo.artifactId
        version = ProjectInfo.nexusVersion + if (useReleaseRepo) "" else "-SNAPSHOT"

        from(components["mastercardDebug_apk"])
    }
}

其中mastercardDebug 是我的Active Build Variant 之一

我总是有以下错误

SoftwareComponentInternal with name 'mastercardDebug_apk' not found

在android项目中使用maven-publishplugin的正确方法应该是什么(同时支持aar和apk模块)?

【问题讨论】:

    标签: android kotlin gradle-kotlin-dsl maven-publish


    【解决方案1】:

    from(components["mastercardDebug_apk"]) 之前使用print(components.names) 验证组件是否存在。也许它只是一个错字

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-16
      • 2016-04-04
      • 2013-02-09
      • 2013-06-07
      • 1970-01-01
      • 2018-07-06
      • 2017-02-03
      • 1970-01-01
      相关资源
      最近更新 更多