Android打包上传AAR文件到Maven仓库的示例

2021-03-23 0 896

1、创建 Android

按以下步骤在项目中创建新的库模块:

  1. 依次点击 File > New > New Module。
  2. 在随即显示的 Create New Module 窗口中,依次点击 Android Library 和 Next。
  3. 为您的库命名,并为库中的代码选择一个最低 SDK 版本,然后点击 Finish。

2、上传aar包至Maven私服

打开新模块 build.gradle 文件,按如下说明修改:

plugins {
  id \'com.android.library\'  // 库模块
  id \'kotlin-android\'   
  id \'maven\'			// 引入maven plugin
}

def snapshotVersionCode = 101
def snapshotVersion = \"1.0.1\"

/* 此处省略 android{} 相关配置 */

dependencies {
  // 友盟基础组件库(所有友盟业务SDK都依赖基础组件库)
  implementation \"com.umeng.umsdk:common:9.3.6\"
  implementation \"com.umeng.umsdk:asms:1.2.0\"
  implementation \"com.umeng.umsdk:apm:1.1.1\"
}

/*快照版 maven上传*/
uploadArchives {
  configuration = configurations.archives
  repositories {
    mavenDeployer {
      repository(url: \'http://nexus.xxxxx.com/repository/maven-snapshots\') {
        authentication(userName: \'userNameXXXX\', password: \'passwordXXXXX\')
      }

      pom.project {
        version snapshotVersion + \'-SNAPSHOT\'
        artifactId \'lib-umeng\'
        groupId \'com.xxxxx\'
        packaging \'aar\'
        description \'lib-umeng Initial submission\'
      }
    }
  }
}

上传aar 到maven
选择右侧Gradle > Module Name > upload ,双击uploadArchives运行

Android打包上传AAR文件到Maven仓库的示例

3、其他项目使用

Project build.gradle添加 maven

allprojects {
  repositories {

	/* 此处省略了其他配置 */
   
    maven { url \'https://dl.bintray.com/umsdk/release\' }  // umeng.umsdk相关maven
    maven { url \'https://nexus.xxxxx.com/repository/maven-snapshots\' }  // 刚刚aar上传的maven
  }
}

Module 中引用,build.gradle添加如下引用

dependencies {
  api (\'com.xxxxx:lib-umeng:1.0.1-SNAPSHOT@aar\') {		// 刚刚生成的aar
    implementation \"com.umeng.umsdk:common:9.3.6\"		// 注意,aar implementation的依赖需要重新引用
    implementation \"com.umeng.umsdk:asms:1.2.0\"
    implementation \"com.umeng.umsdk:apm:1.1.1\"
  }
}

4、QA

maven上传报错:

Execution failed for task \':lib-umeng:uploadArchives\'.
\\> Could not publish configuration \'archives\'
 \\> Failed to deploy artifacts: Could not transfer artifact com.xxxxx:lib-umeng:aar:1.0.1 from/to remote (http://nexus.xxxxx.asia/repository/maven-snapshots): Failed to transfer file: http://nexus.xxxxx.asia/repository/maven-snapshots/com/xxxxx/lib-umeng/1.0.1/lib-umeng-1.0.1.aar. Return code is: 400, ReasonPhrase: Repository version policy: SNAPSHOT does not allow version: 1.0.1.

解决:version snapshotVersion + \’-SNAPSHOT\’ 标记:-SNAPSHOT

参考:developer.android.com/studio/proj…

以上就是Android打包上传AAR文件到Maven仓库的示例的详细内容,更多关于Android打包上传文件到Maven仓库的资料请关注自学编程网其它相关文章!

遇见资源网 Android Android打包上传AAR文件到Maven仓库的示例 http://www.ox520.com/23984.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务