module内包含第三方aar包,完整打包上传maven的方法

我们在做组件化的时候经常遇到这样的场景(maven私有化默认您已经了解或者搭建完成):
我们有一个自己开发维护的Android Module(SDK)内部引用了一个(多个)第三方的aar,当我们打包自己的SDK并上传maven时,引用的aar并不会打包到最终的aar里。
思路是将aar先打包上传至maven,然后自己的module去引用,然后最终打包,我们自己的SDK中的pom.xml就会引用依赖的三方maven地址

本案例使用的是:android studio chipmunk 版本,其他版本入口展示可能不同

新建库项目

在android studio中新建 java-library 类型的 module
在这里插入图片描述

添加第三方aar

将需要上传的aar放在libs下
在这里插入图片描述

配置build.gradle

在当前module的build.gradle文件中做类似如下处理

plugins {
    id 'java-library'
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

//上传到maven
apply plugin: 'maven'
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!下面AAR的文件名改成你放到libs文件夹里的文件名
def coreAarFile = file('libs/AMap3DMap_9.3.1_AMapSearch_9.3.1_AMapLocation_6.1.0_20220704.aar')
artifacts {
    archives coreAarFile
}

uploadArchives {
    repositories {
        mavenDeployer {
            //!!!!!!!!!!!!!!!!!!!!!!!!!!这里配置上传到maven仓库后的  groupId、artifactId、version
            repository(url: "http://172.17.230.145:8081/artifactory/libs-release-local/")
            pom.version = "9.3.1"
            pom.artifactId = "godmap"
            pom.groupId = "com.sdk.components"
            pom.packaging = "aar"
        }
    }
}

打包上传

在这里插入图片描述
然后会在maven中看到上传的资源:
在这里插入图片描述

引用

最后在自己开发的module(SDK)中引入资源
在这里插入图片描述
注意:要引用其.aar类型的包

会发现自己开发的module(SDK)上传maven后其pom如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.sdk.components</groupId>
  <artifactId>ArcMap</artifactId>
  <version>1.1.6</version>
  <packaging>aar</packaging>
  <description>更新SDK 支持不同地图控件</description>
  <dependencies>
    <dependency>
      <groupId>com.sdk.components</groupId>
      <artifactId>godmap</artifactId>
      <version>9.3.1</version>
      <type>aar</type>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <artifactId>*</artifactId>
          <groupId>*</groupId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>androidx.appcompat</groupId>
      <artifactId>appcompat</artifactId>
      <version>1.3.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>androidx.recyclerview</groupId>
      <artifactId>recyclerview</artifactId>
      <version>1.2.1</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

END

如果包含多个aar也是一样,建多个java-library的module,分别上传到maven,宿主module分别重新引用

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值