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

相关推荐
爱笑鱼5 小时前
Handler(一):post 之后,Runnable 到底在哪个线程执行?
android
木木子226 小时前
[特殊字符] 音乐播放器——状态驱动的多媒体控制
android·开发语言·华为·php·harmonyos
雨白6 小时前
C 语言基础:结构体、联合体与枚举
android
阿巴斯甜7 小时前
Android 代码混淆
android
apihz9 小时前
台风实时与历史详情查询免费 API 接口完整教程
android·开发语言·tcp/ip·dubbo·台风·天气预报
浪客川10 小时前
AOSP源码隐藏状态栏
android·aosp
没有了遇见10 小时前
AI Agent 是什么?—— 一文理解 LLM、Memory、Skills、Tools、MCP、Workflow,Context
android·前端·程序员
知行合一。。。11 小时前
LangChain--07--智能体、Agent的基本用法
android·数据库·langchain
御坂嘀喵11 小时前
Speed Tools:一套低侵入的 Android 插件化 + 动态换肤 + 字体切换框架
android·gitee
浮江雾11 小时前
Flutter第三节----Dart中的数据类型
android·开发语言·学习·flutter·入门·函数