Android 发布开源项目到jcenter

简介       

       相信现在Android程序猿们大多都使用了studio进行开发,想必大家对于compile 'com.android.support:appcompat-v7:23.3.0'这种方式引入开源项目肯定不陌生,那么大家有没有自己发布开源项目让别人来引用的想法呢?猜也猜得到,大家都想,那么下面我与大家分享一下自己的上传方法,很是简单哦~


本文采用的方式是bintray-release,上传的项目分为两种情况:

 1、上传单个moudle项目

 2、上传多个moudle项目    


单个moudle项目上传


一、创建你要上传的项目


  

二、注册bintray.com账号

注:jcenter()属于bintray旗下的一个仓库。

我们的上传流程其实就是,从你的Androd Studio,到你的bintray 仓库,最后同步到jcenter仓库。

  1. 进入https://bintray.com/,注册账号。
  2. 注册完成后,需要邮箱激活,也可以选择第三方登录

登录:


登陆后,你可以点击Your Profile->Edit然后就能看到上图的界面。

点击API Key,就可以看到你一段key字符串,把这个copy下放一边,一会上传要用。

三、引入bintray-release

在项目根的build.gradle添加bintray-release的classpath

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. buildscript {  
  2.   repositories {  
  3.     jcenter()  
  4.   }  
  5.   dependencies {  
  6.     classpath 'com.android.tools.build:gradle:2.1.0'  
  7.     classpath 'com.novoda:bintray-release:0.3.4'  
  8.   
  9.     // NOTE: Do not place your application dependencies here; they belong  
  10.     // in the individual module build.gradle files  
  11.   }  
  12. }  
  13.   
  14. allprojects {  
  15.   repositories {  
  16.     jcenter()  
  17.   }  
  18.   tasks.withType(Javadoc) {  
  19.     options {  
  20.       encoding "UTF-8"  
  21.       charSet 'UTF-8'  
  22.       links "http://docs.oracle.com/javase/7/docs/api"  
  23.     }  
  24.   }  
  25. }  

您准备上传moudle的build.gralde
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. apply plugin: 'com.android.library'  
  2. apply plugin: 'com.novoda.bintray-release'//添加  
  3.   
  4. android {  
  5.  lintOptions {  
  6.     abortOnError false  
  7.   }   
  8. }  
  9.   
  10. dependencies {  
  11.     //保持不变  
  12. }  
  13.   
  14. //添加  
  15. publish {  
  16.     userOrg = 'walid1992'//bintray.com用户名  
  17.     groupId = 'com.walid'//jcenter上的路径  
  18.     artifactId = 'retrofit2-tools'//项目名称  
  19.     publishVersion = '1.0.0'//版本号  
  20.     desc = 'retrofit2 tools to download file '//描述  
  21.     website = 'https://github.com/walid1992/retrofit2-tools'//网站,不重要,尽量模拟github上的地址  
  22. }  


若成功,最终引入的方式为:

compile 'com.walid:retrofit-tools:1.0.0

上传

上传很简单,执行下面的代码即可

mac上传:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ./gradlew clean build bintrayUpload   
  2. -PbintrayUser=hyman   
  3. -PbintrayKey=xxxxxxxxxxxxxxxxxxxxxx   
  4. -PdryRun=false  
windows上传:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. gradlew clean build bintrayUpload   
  2. -PbintrayUser=hyman   
  3. -PbintrayKey=xxxxxxxxxxxxxxxxxxxxxx   
  4. -PdryRun=false  

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


点击底部的Terminal即可,注意下你当前的路径是当前项目下,然后enter运行。

稍作等待,当运行完成,看到BUILD SUCCESSFUL就没问题了,如果有什么问题呢,根据log排查下。

到此就上传完成了~

访问https://bintray.com/你的用户名/maven,即可看到如下界面

看到:


看到您上传的项目了,你可以点击进去看该库的一些信息,但此时不能够直接被引用。

点击进去该库,按照下图,点击Add To jcenter


简单写一下对该开源库的描述


ok,您成功了,但是目前依然不能直接引用,你需要等待bintray的工作人员审核,审核通过会给你发送站内Message,并且Add to Jcenter那个按钮就不见了。

多个moudle项目上传


1、项目根目录build.gradle配置,加入了ext模块,主要用于管理多moudle

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. buildscript {  
  2.   repositories {  
  3.     jcenter()  
  4.   }  
  5.   dependencies {  
  6.     classpath 'com.android.tools.build:gradle:2.1.0'  
  7.     classpath 'com.novoda:bintray-release:0.3.4'  
  8.   
  9.     // NOTE: Do not place your application dependencies here; they belong  
  10.     // in the individual module build.gradle files  
  11.   }  
  12. }  
  13.   
  14. allprojects {  
  15.   repositories {  
  16.     jcenter()  
  17.   }  
  18.   tasks.withType(Javadoc) {  
  19.     options {  
  20.       encoding "UTF-8"  
  21.       charSet 'UTF-8'  
  22.       links "http://docs.oracle.com/javase/7/docs/api"  
  23.     }  
  24.   }  
  25. }  
  26.   
  27. //添加  
  28. ext {  
  29.   userOrg = 'walid1992'  
  30.   groupId = 'com.walid'  
  31.   uploadName = 'StrongMVC'  
  32.   publishVersion = '1.0.0'  
  33.   desc = '强化版mvc设计模式 '  
  34.   website = 'https://github.com/walid1992/StrongMVC'  
  35.   licences = ['Apache-2.0']  
  36. }  

2、moudle中build.gradle配置,几个moudle配置几乎一样,只有artifactId有区别,每个moudle都有自己的名字

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. apply plugin: 'com.android.library'  
  2. apply plugin: 'bintray-release'  
  3. android {  
  4. }  
  5. dependencies {  
  6. }  
  7. publish {  
  8.     artifactId = 'event'  
  9.     userOrg = rootProject.userOrg  
  10.     groupId = rootProject.groupId  
  11.     uploadName = rootProject.uploadName  
  12.     publishVersion = rootProject.publishVersion  
  13.     desc = rootProject.description  
  14.     website = rootProject.website  
  15.     licences = rootProject.licences  
  16. }  

上传操作如出一辙。。。

到此发布项目到jcenter介绍完毕,希望对大家有所帮助哦~




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值