一.准备工作

1.登录https://bintray.com/注册一个帐号,并获取Api Key

2.创建一个Maven仓库



3.创建一个package

二.发布jar到jcenter

1.在project下build.gradle中添加如下:

dependencies{}中加入

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1'classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

allprojects{}中加入,防止出现编码问题,导致gradle编译不通过

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

}

2.创建library工程Module,然后在Module下build.gradle中添加如下信息:

apply plugin: 'com.github.dcendents.android-maven'apply plugin: 'com.jfrog.bintray'

group = '真实的包名'

version = '版本号'

生成javadocjar和javasourcejar的任务

//Jar包配置task sourcesJar(type: Jar) {    from android.sourceSets.main.java.srcDirs    classifier = 'sources'}//Javadoc Jar包配置task javadoc(type: Javadoc) {    source = android.sourceSets.main.java.srcDirs   // classpath += project.files(android.getBootClasspath().join(File.pathSeparator))    //解决打包过程中有第三方jar的问题,这样就可以把工程中依赖的第三方jar包,打包进来    classpath += project.files(configurations.compile.files,android.getBootClasspath().join(File.pathSeparator))}task javadocJar(type: Jar, dependsOn: javadoc) {    classifier = 'javadoc'    from javadoc.destinationDir}//上传到maven或jcenter的Jar包的类型artifacts {    archives javadocJar    archives sourcesJar}
/* *上传配置 */Properties properties = new Properties()boolean isHasFile = falseif (project.rootProject.file('local.properties') != null){    isHasFile = true    properties.load(project.rootProject.file('local.properties').newDataInputStream())}bintray {    user = isHasFile ? properties.getProperty("bintray.user") : System.getenv("bintray.user") //用户名    key = isHasFile ? properties.getProperty("bintray.apikey") : System.getenv("bintray.apikey") //key    configurations = ['archives']    pkg {        repo = "对应bintray的maven仓库名" //仓库名
      name="对应bintray的package包名"
websiteUrl = "网页首页地址"//也可以用GitHub的首页网址 vcsUrl = "project git" //也可以使用GitHub的git地址 licenses = [ "Apache-2.0"] publish = true }}

3.在project下local.properties中添加如下:

你在Bintray上的帐户名和apikey

bintray.user=userid

bintray.apikey=apikey

4.通过Android Studio右上角Gradle窗口执行命令

在library下的other中找到install命令双击执行,看到build successful后执行publishing下命令bintrayUpload,看到build successful说明项目已上传成功

三.将项目发布至Jcenter中央仓库

登录bintray网站找到maven下的包,进入包详情页第一次进入可能会提示你有几个文件需要publish,点击publish即可。然后可以看到右下角有Add to Jcenter按钮,点击进入后直接点击Send发送即可将项目发布至Jcenter,管理员审核之后就可以通过Gradle依赖方式使用


更多相关文章

  1. ButterKnife 8.4添加使用
  2. 如何解压system.img
  3. IIS 添加mime 支持 apk,exe,.woff,IIS MIME设置 ,Android(安卓)apk
  4. Android(安卓)App性能之--cpu占用率
  5. 我的Android进阶之旅------>解决错误:You need to use a Theme.Ap
  6. android adb录屏命令
  7. android 屏幕录制-screenrecord
  8. android studio 中 java.lang.NoClassDefFoundError:retrofit2.R
  9. umeng android 统计类部署

随机推荐

  1. Android(安卓)EditText实现字符过滤
  2. Android 多个Activity选项卡实现
  3. android hook getdeceiveid
  4. Android中创建对话框
  5. Android(安卓)Stduio出现“required plug
  6. android ExpandableListView ExpandableL
  7. pandaboard ES学习之旅——4 Android源代
  8. Android 中文 API (29) ―― CompoundButto
  9. 跟着做 Android NDK学习入门如此简单(二)
  10. android数据存取的四种方式