第一步:

创建一个新项目,创建自己的library module。

android studio个人主页订单 android studio个人中心_github


在library中只有一个返回字符串的工具类,只是为了测试。在app中添加这个依赖,正常运行。

第二步:
在项目的build.gradle中的dependencies中添加
classpath ‘com.novoda:bintray-release:0.9.1’

dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.novoda:bintray-release:0.9.1'
    }

官网github有最新依赖版本,可修改最新版本:
GitHub 官网:https://github.com/novoda/bintray-release

添加完sync一下,如下图:

android studio个人主页订单 android studio个人中心_android_02


第三步:

去注册bintray,注册网址 https://bintray.com/signup/oss

android studio个人主页订单 android studio个人中心_上传_03


用github或者谷歌账号注册都行,但是验证的时候不能用qq或者163邮箱。我用的是gmail 邮箱。登录通过如下:

android studio个人主页订单 android studio个人中心_上传_04


点击Add New Repository建立一个新的存储库,我是已经建立好了。

android studio个人主页订单 android studio个人中心_android_05


如图填写好信息就行了。然后在新建的仓库中新建一个包

android studio个人主页订单 android studio个人中心_github_06


android studio个人主页订单 android studio个人中心_上传_07

至此文件的提交仓库已经创建好了

要注意的就是和这个Name的填写,要和后面android studio的配置的名字一致。不然上传会失败。

第四步:
配置androidstudio上传信息:
打开要上传的module中的build.gradle。
在顶部添加:

apply plugin: 'com.novoda.bintray-release'

在末尾添加:

publish {
    userOrg = 'yinzhipengwork'                               //bintray.com 账号用户名
    groupId = 'com.yzpUtils'                                 //唯一 id,最后依赖的库名组成部分之一
    artifactId = 'StringUtillib'                             //仓库名
    publishVersion = '1.0.0'                                 //版本号
    desc = 'hello jcenter'                                   //描述
    website = 'https://github.com/YZP0721'                   //开源项目网址
}

如下图:

android studio个人主页订单 android studio个人中心_github_08


android studio个人主页订单 android studio个人中心_上传_09


userOrg要用你注册bintray的名字,artifactId要用你之前创建包填写的名字。可以参照如下图:

android studio个人主页订单 android studio个人中心_上传_10


第五步:

上传library:

在android studio的控制台

android studio个人主页订单 android studio个人中心_android_11


运行如下命令:

gradlew clean build bintrayUpload -PbintrayUser=xxxx -PbintrayKey=xxxxx -PdryRun=false有两处的值,通过如下获取:

android studio个人主页订单 android studio个人中心_上传_12


android studio个人主页订单 android studio个人中心_android_13


android studio个人主页订单 android studio个人中心_github_14


PbintrayUser为你注册的名字,即userOrg的值。

PbintrayKey是你的APIkey的值。

运行!!上传成功!如下图:

android studio个人主页订单 android studio个人中心_github_15


android studio个人主页订单 android studio个人中心_上传_16


可以看到已经有上传信息了。下面是如何使用:

去bintray能看到你刚才上传的项目。

android studio个人主页订单 android studio个人中心_github_17


接下来可以新建一个测试的项目:

因为我们上传的项目还没有提交至jcenter审核,所以暂时还需要添加maven:

在项目的build.gradle中添加 (就是上图标出来的地址)

maven { url 'https://dl.bintray.com/yinzhipengwork/maven' }

在app module的build.gradle中添加依赖(也是上图标出来的地址)

implementation 'com.yzpUtils:StringUtillib:1.0.0'

android studio个人主页订单 android studio个人中心_jcenter_18


android studio个人主页订单 android studio个人中心_jcenter_19


运行代码:

android studio个人主页订单 android studio个人中心_jcenter_20


android studio个人主页订单 android studio个人中心_github_21


成功拿到之前封装返回的字符串,完美撒花。还有最后一步:

提交jcenter:

android studio个人主页订单 android studio个人中心_github_22


审核成功后就可以直接用

implementation 'com.yzpUtils:StringUtillib:1.0.0'

这一行代码就可以引用了,就不需要maven了。