Android提交mvn

在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/ 查看是否上传成功

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值