Android提交mvn

xiaoxiao2021-02-28  127

在Android Studio中把某个项目提交到mvn上后,其他的项目就可以直接引用这个项目,比如把某个项目作为外部包,就可以把这个项目上传到mvn上,这样其他项目就可以直接在gradle设置下就可以了,使用很方便。 把项目上传到mvn的步骤如下: 1,打开项目的app目录下的 build.gradle文件,开头这样写:

apply plugin: 'com.android.library' apply plugin: 'maven-publish' apply plugin: 'com.jfrog.artifacto def libraryGroupId = 'com.lvchuang' def libraryArtifactId = 'view-pager-indicator' def libraryCode = 1 def libraryVersion = '1.4'

libraryGroupId、libraryArtifactId、libraryVersion对应了项目里面的

compile 'com.lvchuang:view-pager-indicator:1.4'

build.gradle文件里面的代码如下:

apply plugin: 'com.android.library' apply plugin: 'maven-publish' apply plugin: 'com.jfrog.artifactory' def libraryGroupId = 'com.lvchuang' def libraryArtifactId = 'view-pager-indicator' def libraryCode = 1 def libraryVersion = '1.4' android { compileSdkVersion 17 buildToolsVersion "25.0.2" defaultConfig { minSdkVersion 4 targetSdkVersion 4 versionCode libraryCode versionName libraryVersion } buildTypes { release { minifyEnabled false } } } dependencies { compile 'com.android.support:support-v4:18.0.0' } publishing { publications { aar(MavenPublication) { groupId libraryGroupId version libraryVersion artifactId libraryArtifactId artifact("$buildDir/outputs/aar/app-release.aar") pom.withXml { def root = asNode() def license = root.appendNode('licenses').appendNode('license') license.appendNode('name', 'The Apache Software License, Version 2.0') license.appendNode('url', 'http://www.apache.org/licenses/LICENSE-2.0.txt') license.appendNode('distribution', 'repo') } } } } artifactory { contextUrl = "${artifactory_contextUrl}" publish { repository { repoKey = 'libs-release-local' username = "${artifactory_user}" // The publisher user name password = "${artifactory_password}" // The publisher password maven = true } defaults { publishArtifacts = true publications('aar') publishPom = true } resolve { repository { repoKey = 'jcenter' username = "${artifactory_user}" // The resolver user name password = "${artifactory_password}" // The resolver password } } } }

2,然后如下设置: 点击侧边栏的Gradle,弹出如下窗口:

在弹出的窗口输入: clean assembleRelease generatePomFileForAarPublication artifactoryPublish 点击确定就好了

3,登录 http://mvn.guo.lol/ 查看是否上传成功

转载请注明原文地址: https://www.6miu.com/read-30406.html

最新回复(0)