android studio 使用maven-publish 插件上传aar到远程maven仓库

上传插件编写

1、在工程目录下添加upload.gradle文件

kotlin 复制代码
apply plugin: 'maven-publish'


def RELEASE_REPOSITORY_URL = 'http://xxx.xx.com/artifactory/repository/release/'
def SNAPSHOT_REPOSITORY_URL =  'http://xxx.xx.com/artifactory/repository/snapshot/'

def USERNAME = "developer"
def PASSWORD = "developer"

afterEvaluate {
    publishing {
        //配置maven 仓库
        repositories { RepositoryHandler handler ->
            handler.maven { MavenArtifactRepository mavenArtifactRepository ->
                allowInsecureProtocol(true)
                url = VERSION.endsWith('SNAPSHOT') ? SNAPSHOT_REPOSITORY_URL : RELEASE_REPOSITORY_URL
                credentials {
                    username USERNAME
                    password PASSWORD
                }
            }
        }

        //配置发布产物
        publications { PublicationContainer publicationContainer ->
            //发布 snapshot 包
            debug(MavenPublication) {
                from components.debug
                artifact sourceJar
                groupId = GROUP_ID
                artifactId = ARTIFACT_ID
                version  = VERSION
            }

            release(MavenPublication) {
                // Applies the component for the release build variant.
                from components.release
                artifact sourceJar
                groupId = GROUP_ID
                artifactId = ARTIFACT_ID
                version  = VERSION
            }
        }
    }
}


//增加上传源码的task
task sourceJar(type:Jar){
    from android.sourceSets.main.java.srcDirs
    archiveClassifier = "source"
}

2、在要上传的module的build.gradle添加插件

kotlin 复制代码
plugins {
    id 'com.android.library'
}

apply from: "../upload.gradle"

3、在要上传的module配置对应的aar信息,新建gradle.properties

kotlin 复制代码
GROUP_ID=com.xx.card
ARTIFACT_ID=card
VERSION=0.0.1

遇到的问题以及解决方案

1、如何区分上传SNAPSHOT和正式版本?

url = VERSION.endsWith('SNAPSHOT') 插件内通过版本字符串中是否含有该字段

2、多渠道打包如何上传对应渠道

from components.debug,把debug修改成对应渠道即可。参考Build Variant

相关推荐
随遇丿而安4 小时前
第11周:Activity 跳转与传值 + 跳转优化
android
私人珍藏库5 小时前
[Android] BBLL 开源第三方B哩电视TV端
android·app·生活·工具·多功能
杉氧7 小时前
跨平台资源管理:一套代码如何搞定 Android、iOS 和 Web 的图片与多语言?
android·架构·android jetpack
安卓修改大师8 小时前
安卓修改大师实战:从反编译到定制的完整APK修改指南
android
柚鸥ASO优化9 小时前
安卓APP推广的“降本增效”密码:守好商店内,打好商店外
android·aso优化
我是一颗柠檬10 小时前
【Java项目技术亮点】EXPLAIN深度分析与慢查询治理
android·java·开发语言
Android-Flutter10 小时前
android compose shadow 阴影 使用
android·kotlin·compose
帅次10 小时前
Android 高级工程师面试:Java 多线程与并发 近1年高频追问 22 题
android·java·面试
2501_9437823510 小时前
【共创季稿事节】摩斯电码转换器:编码表与双向转换的实现
android·华为·鸿蒙·鸿蒙系统
STCNXPARM11 小时前
Android selinux详解
android·selinux