android studio maven 插件开发,使用 Maven Publish 插件

Android Gradle 插件 3.6.0 及更高版本支持 Maven Publish Gradle 插件,可让您将构建工件发布到 Apache Maven 代码库。Android Gradle 插件会为应用或库模块中的每个构建变体工件创建一个组件,您可以使用它来自定义要发布到 Maven 代码库的发布内容。

Android 插件所创建的组件取决于模块是否使用应用或库插件,如下表所述。

Android Gradle 插件

发布内容工件

组件名称

com.android.library

AAR

components.variant

com.android.application

APK 和可用的 ProGuard 或 R8 映射文件的 ZIP

components.variant_apk

com.android.application

Android App Bundle (AAB)

components.variant_aab

注意:如果您的应用包含功能模块,就不能以 APK 的形式发布,而应使用 App Bundle 来发布您的应用。

以下代码示例为 AAR 库的发布和调试构建变体创建了发布内容。每项发布内容都会应用匹配的组件,并自定义所生成 POM 的属性,如 Maven 坐标。

// Because the components are created only during the afterEvaluate phase, you must

// configure your publications using the afterEvaluate() lifecycle method.

afterEvaluate {

publishing {

publications {

// Creates a Maven publication called "release".

release(MavenPublication) {

// Applies the component for the release build variant.

from components.release

// You can then customize attributes of the publication as shown below.

groupId = 'com.example.MyLibrary'

artifactId = 'final'

version = '1.0'

}

// Creates a Maven publication called “debug”.

debug(MavenPublication) {

// Applies the component for the debug build variant.

from components.debug

groupId = 'com.example.MyLibrary'

artifactId = 'final-debug'

version = '1.0'

}

}

}

要创建发布内容来以 APK 的 ZIP 文件或 Android App Bundle (AAB) 的形式发布您的应用,只需使用适当的组件即可,如下所示。

afterEvaluate {

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'

}

}

}

在您创建发布内容后,Maven Publish 插件会创建发布任务,您可以通过这些任务将工件发布到您指定的代码库。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值