13

Android快速发布项目到jcenter

 3 years ago
source link: http://www.androidchina.net/6416.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

最近在整理项目的时候,想要上传至Jcenter,可以让大家一句代码就可以引入。就在网上寻找,然而网上有些方法实在是太麻烦,故写此篇文章将心酸历程写下,让各位老司机少走弯路,快速发布。而且最近更坑人的是bintray改版了,所以现在很多人上传成功代码后发现没有Add to Jcenter按钮,天啦撸,坑死人。

下面由我带着各位一步步走向大牛之路,走向幸福奔小康。本文准备采用鸿洋推荐的bintray-release这个插件,个人感觉比gradle-bintray-plugin要方便很多。

第一步:申请Bintray账号并获取所需信息(非常重要,仔细看步骤)

为什么要注册这个账号呢,因为jcenter()属于bintray旗下的一个仓库。

所以各位大兄弟需要一个bintray的账号撒。注册网址:https://bintray.com/

走到这里,你已经错完了,除非你是企业用户或者是等待30天以后,为什么呢?看图说话!

QQ%E6%88%AA%E5%9B%BE20170206163746.png

个人免费版的注册地址https://bintray.com/signup/oss

注意一下邮箱问题:不能用QQ,163等,如果用的Github快速登录,也要注意邮箱问题。

获取信息:登陆后在首页右上角点击用户名进入个人主页,然后点击用户名下面的Edit Profile进入个人信息编辑页面,接下来点击页面左边列表的最后一项API Key,保存下来,待会儿要用 。
如图所示点击最右边箭头指示的复制按钮即可复制你的API Key:

第二步:引入bintray-release

首先你应该有一个自己待上传的项目。我在这里用我的一个Android library模拟一个简单的项目。tobebetter是个Android library,主要用来存放一一个数字时钟,我们现在要将其上传到jcenter。

项目的build.gralde引入

在你的项目的build.gradle添加bintray-release的classpath,注意是项目的build.gradle,不是module的,MyApplication3/build.gradle。

classpath 'com.novoda:bintray-release:0.3.4'

配置待上传moudle的build.gralde

来到你想要上传的module,针对文章开始的图即MyApplication3/tobebetter/build.gradle。

apply plugin: 'com.novoda.bintray-release'//添加

//添加
 publish {
    userOrg = 'shantecnology'//bintray.com用户名
    groupId = 'com.halloandroid'//jcenter上的路径
    artifactId = 'tobebetter'//项目名称
    publishVersion = '1.0.0'//版本号
    desc = 'this is for test'//描述,不重要
    website = 'https://github.com/shanlovana/tobebetter'//网站,最好有,不重要
}

按照图片知道编写即可,细节有注释了,假设按照上述的编写,并上传成功,那么你的项目最终引入的方式为:

compile 'com.halloandroid:tobebetter:1.0.0

完成上面的配置,我们就开始准备上传了。

上传代码至Bintray

上传很简单,在Android Studio的Terminal面板进行,执行下面的代码即可:

windows系统:

  gradlew clean build bintrayUpload 
 -PbintrayUser=shantecnology  
 -PbintrayKey=xxxxxxxxxxxxxxxxxxxxxx 
 -PdryRun=false

Mac系统:

 ./gradlew clean build bintrayUpload 
 -PbintrayUser=shantecnology  
 -PbintrayKey=xxxxxxxxxxxxxxxxxxxxxx 
 -PdryRun=false

user就是用户名,key就是我们刚才的Api key,dryRun是一个配置参数,当为true的时候,会运行所有的环节,但是不会上传。

然后就是等待,当运行并上传完成,看到BUILD SUCCESSFUL就没问题了,如果有问题,根据log排查下。

到此就上传完成,是不是很快呢!

进入我们的上传的空间中就会看到我们的项目,例如我刚上传的地址:https://bintray.com/shantecnology/maven

你上传的地址在:https://bintray.com/你的用户名/maven

提交的时候要做一个简短的英文描述,尽量不要用中文。

教程到此就结束了,不过目前还是不能直接引用的,你需要等待bintray的工作人员审核,审核通过会给你发送站内Message,大概两个小时左右,并且Add to Jcenter那个按钮就消失了。

注意事项:

乱码问题:

注释中有中文,可能会出现:编码GBK的不可映射字符

1,项目的build.gradle中添加:

allprojects {
tasks.withType(Javadoc) {
    options{
        encoding "UTF-8"
        charSet 'UTF-8'
        links "http://docs.oracle.com/javase/7/docs/api"
    }
  }
}

2,其实我觉得完全可以将中文注释换成英文,毕竟我们是要成为大佬的男人,你懂得!百度翻译,必应翻译。。。。

版本更新

我们上传完成后,肯定会涉及到更新问题,那么How to update呢?

publish {
   userOrg = 'shantecnology'//bintray.com用户名
   groupId = 'com.halloandroid'//jcenter上的路径
   artifactId = 'tobebetter'//项目名称
   publishVersion = '2.0.0'//版本号
   desc = 'this is for test'//描述,不重要
   website = 'https://github.com/shanlovana/tobebetter'//网站,最好有,不重要
}

大部分都不用动,只要修改下版本号就可以了,修改完成后,执行上传那段代码,上传完成后,点击下图按钮即可。更新的审核比较快,稍等一下就行了。

QQ%E6%88%AA%E5%9B%BE20170206180203.png

教程到此结束,是不是 so easy !呢???

原文链接:http://blog.csdn.net/zhcswlp0625/article/details/54895584

作者:zhcswlp0625

转载请注明:Android开发中文站 » Android快速发布项目到jcenter


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK