Android Studio发布项目到Maven和Jcenter

文章概述:

本篇文章记录,在Android Studio上,编译项目通过bintray发布到Maven仓库,并同步到Jcenter仓库。

bintray用户配置

(1)在bintray官网注册账号

在官网最底下有个选项才是个人用户注册的入口,如图:

image

(2)在用户中心,获取用户名和Api Key.
(3)新建一个maven仓库,然后添加项目moudle

在Android Studio 项目中配置

(1)创建工程,在工程目录下local.properties文件最后添加bintray用户名和Api Key
bintray.user=username
bintray.apikey=apikey
(2)项目gradle下添加bintray发布项目插件的依赖
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.2'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
    classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
}
(3)在需要发布的moudle的gradle文件中配置发布信息

如:library的gradle

ext {
    bintrayRepo = 'maven' //maven仓库名称,直接写maven即可
    bintrayName = 'library' //项目名称(包名)

    publishedGroupId = 'com.ls.library' //组织id
    libraryName = 'library' //项目名称
    artifact = 'library' //项目的通用名称

    //描述性文字
    libraryDescription = 'library description information'
    //项目github上的地址
    siteUrl = 'https://github.com/cnlius/JcenterTest'
    //项目github上的git仓库地址
    gitUrl = 'https://github.com/cnlius/JcenterTest.git'
    //版本号
    libraryVersion = '1.0.1' 
    //开发者信息设置(任意)
    developerId = 'liusong'
    developerName = 'liusong'
    developerEmail = 'jsmrliu@gmail.com'

    licenseName = 'The Apache Software License, Version 2.0'
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    allLicenses = ["Apache-2.0"]
}

// 使用bintray插件
// Place it at the end of the file
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'

终端中依次执行发布到bintray的maven仓库命令

gradlew install
gradlew bintrayUpload

项目发布后会在bintray中看到相关信息,找到如下图的配置信息:

image

这个信息会在使用这个项目的时候需要。

注意:在maven仓库项目信息右下角有Add to Jcenter按钮,点击即可发布到Jcenter仓库上,可能需要点时间才能看到发布成功.

发布后的项目的使用

  • 在开发的项目gradle添加依赖来中使用jcenter开源的项目:
dependencies {
    // 格式 GROUP_ID:ARTIFACT_ID:VERSION 
    //(具体值要参考上面提到的maven build settings项目配置信息)
    compile 'com.ls.library:library:1.0.1'
}
  • 如果项目没有添加到jcenter,则需要指明maven地址才能使用
repositories {
    jcenter() //使用jcenter
    mavenCentral(); //使用maven
    //maven远程仓库地址
    maven {
        url 'https://dl.bintray.com/liusong/maven'
    }
}

dependencies {
    compile 'com.ls.library:library:1.0.1'
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值