按以下步骤在项目中创建新的库模块:
打开新模块 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运行
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" } }
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仓库的资料请关注其它相关文章!