Android Library 发布到 Jcenter

创建 Jcenter 账号

提供官网注册账号地址:官网
* 注册账号,这里有一个容易忽略的坑:注册账号的时候,大家肯定是会被很明显的位置吸引,但是,很不幸的告诉你,如果这一步就做错了,下面的内容不用看了;
@注册账号 | center |

图中的两种注册账户:
1. 普通账户
2. Open source plan (开源) 账户
而我们想要将Libray开放处理,则必须使用第二种注册账户方式;
@账号登陆 | center |

获取API-Key

@获取appkey | center |
@获取appkey | center |
通过图中所示方式,获取 API-key,保存起来,后续上传时会用到

仓库的创建

@创建仓库 | center |
@命名要求 | center |
如图示:
命名时需要注意:由于是通过 bintray-release插件上传到 jcenter ,其命名必须为:maven,不让上传时会提示:HTTP/1.1 404 Not Found [message:Repo ‘maven’ was not found]

项目中配置

项目引入 bintray—release 插件

在项目的 build.gradle 文件中增加如下配置

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        // 增加下面一行代码
        classpath 'com.novoda:bintray-release:0.4.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

目前 bintray-relase 插件 更新到了 0.4.0 版本

LibrayrModule 中 build.gradle 中配置

apply plugin: 'com.android.library'
// 增加
apply plugin: 'com.novoda.bintray-release'

android {
    ...
}

dependencies {
    ...
}

// 增加
publish {
    userOrg = 'qazxsw' // bintray.com用户名
    groupId = 'com.qazxsw' // jcenter上的路径
    artifactId = 'basetools' // 项目名称
    publishVersion = '1.0.0' // 版本号
    desc = 'Oh hi, this is a nice description for a project, right?'//描述,不重要
    website = 'https://github.com/username/projectname'// 项目的地址,一般情况下是 github 上的开源项目(oschina...等也可)
}

如果你已经执行到了这一步,恭喜你,已经快了,再前行一步就到为了…

Library 的编译上传

在 Android Studio 的 Terminal 窗口 内执行

windows:

gradlew clean build bintrayUpload 
-PbintrayUser=用户名
-PbintrayKey=API-key 
-PdryRun=false

---- 华丽的分隔线 -----

linux:

./gradlew clean build bintrayUpload 
-PbintrayUser=用户名
-PbintrayKey=API-key 
-PdryRun=false

其中
PbintrayUser 使用你的 Bintray 的用户名
PbintrayKey 使用你的 Bintray 的Api-key (上面已经获取到了)

当运行完成,看到BUILD SUCCESSFUL就OK了;
如果你以为到这里就ok了,那就萌萌哒了…

提交审核

你可以通过直接输入 https://bintray.com/用户名/maven 可以打开仓库,可以看到你刚刚提交的 Librayr以及你定义的版本号
@仓库中Library信息 | center |
@仓库中Library信息 | center |
打开 Library 点击 AddToJcenter 按钮,慢慢等待审核,如果通过了审核,恭喜各位看官,已经可以在项目中愉快的使用你的 Library 了;

总结

主要分为几个步骤
1. 申请账号(注意账号类型)— 很重要,是基础
2. 引入 bintrary-release 插件,填写相关配置信息
3. 上传命令提交到 Bintrary 上的仓库
4. 提交到 Jcenter 审核

猜你喜欢

转载自blog.csdn.net/qq_16251833/article/details/80110494