上传Library到bintray(jcenter)
首先简单的说明下,上传libary到jcenter的好处。Android开发者可以在gradle中用一句话即可引用你写的库。
就像这样:
compile ’com.android.support:support-v4:23.4.0‘
是不是很酷!
好了,废话少说,进入正题吧。
—————————————————————————————————————
在RootProject,也就是项目的build.gradle中加入
classpath 'com.novoda:bintray-release:0.3.4'
就像这样:
Paste_Image.png并在这个gradle文件下面添加
def rxLifeCycleVersion = "0.6.1"
ext{
//-------- bintray config -----------
userOrg = "wind0ws"//bintray.com用户名
groupId = "com.threshold"//jcenter上的路径
publishVersion = rxLifeWithMvpVersion//版本号
desc = "It is a mosby mvp with RxLife Library"//类库的描述,不重要
website = "https://github.com/wind0ws/RxLifecycleWithMvp"//类库的网站,不重要
uploadName = "RxlifecycleWithMvp" //上传在bintray的文件夹
licences = ["Apache-2.0"]
// --------bintray config-----
}
就像这样:
Paste_Image.png之后在需要上传的module中
apply plugin: 'com.novoda.bintray-release'
就像这样:
Paste_Image.png并在这个要上传的module中的gradle中写:
//添加
publish {
artifactId = 'rxlifecyclewithmvpviewstate'//模块名称
userOrg = rootProject.userOrg
groupId = rootProject.groupId
uploadName = rootProject.uploadName //模块上传后所在的文件夹名称
publishVersion = rootProject.publishVersion//模块版本号
desc = rootProject.description//模块的描述
website = rootProject.website //模块的网站
licences = rootProject.licences //模块的licences
}
其中artifactId是这个Module的名称。
就像这样:
这样配置后别人引用你的的gradle就是:
compile 'com.threshold:rxlifecyclemvp:0.6.1'
也就是 groupId : artifactId : version
最后是上传了。 打开AS底部的Terminal,注意这个Terminal的打开时的路径是当前项目而不是某个Module路径(默认情况就是Project路径)在里面敲: 注意这些都在一行。输入完成后才敲回车执行。
./gradlew clean build bintrayUpload -PbintrayUser=YourBintrayUserName -PbintrayKey=YourKey -PdryRun=false
如果提示gradlew 没有permission,那么请在终端给这个文件增加运行权限
chmod +x gradlew
其中bintrayUser就是bintray.com中的用户名
key可以在bintray.com中获取,
之后看终端日志吧。有错的改错,BuildSuccessful就是成功了。之后去bintray.com就能看到你上传的了。
成功类似这样:
如果提示Peer Not Authenticate,那么请关闭Proxy,彻底关闭。并在AS设置中设成不使用代理。
最最后重要的一点:
上面BuildSuccessful并不是代表别人就可以引用你的库了。
第一次上传的时候只是上传到了bintray.com上面。并没有到jcenter
所以在第一次成功上传后还需要到bintray.com上面发请求给jcenter,请求将你的库加入到jcenter库中,类似下图,点击Add to center,然后填写请求内容。
等待几个小时,如果jcenter成功收纳你的库,你就能在你的jcenter中看到jcenter的图标,就像这样:
至此,别人就能尽情的使用 compile "xx.xx:xxx:0.0.1"这样的gradle配置来引用你的库了。以后如果你更新了代码,更新库只需要执行
./gradlew clean build bintrayUpload -PbintrayUser=YourBintrayUserName -PbintrayKey=YourKey -PdryRun=false
这个命令就可以了。
关注我的公众号.jpg
网友评论