1.首先在bintray(https://bintray.com)上注册账号,最好用gmail邮箱注册,或者选择第三方登录也可以
2.创建仓库,如:
3.在对应仓库右边点击create package 创建项目目录,如:
4.在项目根目录的build.gradle 中添加 插件依赖,如:
5.在需要上传的模块目录下,修改build.gradle ,添加以下内容:
apply plugin: 'com.novoda.bintray-release'
//add for publish lintOptions{ abortOnError false //这是添加的 checkReleaseBuilds false //这是添加的 }
publish{ userOrg = 'winson1990' //你debintray 账号登录名 groupId = 'org.dpower.dpsmartcommunity.smarteye' //这个对应jcenter上的路径 artifactId = 'smarteye' //这个对应你的项目名 publishVersion = '1.0.1' //版本号,以后控制版本就通过这个版本号 desc = 'this is a Test' website = 'http://www.d-power.com.cn/' }
如:
6.上传代码到库
在Android Studio的Terminal面板进行,执行下面的命令即可:
windows系统: gradlew clean build bintrayUpload -PbintrayUser=xxx -PbintrayKey=xxxxxxxxxxxxxxxxxxxxxx -PdryRun=false
Mac系统: ./gradlew clean build bintrayUpload -PbintrayUser=xxx -PbintrayKey=xxxxxxxxxxxxxxxxxxxxxx -PdryRun=false
注:user就是用户名,key就是我们刚才的Api key,dryRun是一个配置参数,当为true的时候,会运行所有的环节,但是不会上传。
最后看到这样的信息就算上传成功!
这时候如果需要引用刚才上传的库,需要这样配置:
(1)、项目根目录gradle文件中这样配置(xxx为你的用户名):
(2)、最后还需要在需要引用的地方添加上以下依懒 compile 'com.helloandroid:mylibrary:1.0.0
当然这样每次要添加依懒时,都要执行步骤一,这样是很不友好的。不过只要我们完成以下步骤,就可以只需要执行步骤2就可以添加了!
打开网址:https://bintray.com/你的用户名/maven,进入以下页面,
点击库名字,跳转到
再点击Add to JCenter
最后填写信息提交,当审核通过时,会发站内信通知您。通过时就只需要执行步骤2就可以添加依懒!
6. 更新版本
更新版本很容易,只需要更改下库版本号就可以!
publish {
userOrg = 'xxx'//bintray.com用户名
groupId = 'com.helloandroid'//jcenter上的路径
artifactId = 'mylibrary'//项目名称
publishVersion = '1.0.1'//版本号
desc = 'this is for test'//描述,不重要
website = 'https://github.com/kuyue'//网站,最好有,不重要
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
执行发布命令后,在网站上执行以下操作即可:
7. 解决bug
执行命令行时,可能会出现以下错误信息
(1)如图
解决方法:在要上传的gradle 文件的android节点里面添加以下代码:
lintOptions {
abortOnError false
}
- 1
- 2
- 3
(2)如图
出现Could not create package是因为插件创建不了库。
解决方法:我们手动创建一个
(3)有可能出现乱码问题
解决问题:在项目根目录gradle文件中添加以下代码
allprojects {
tasks.withType(Javadoc) {
options{
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}
}