使用Gradle发布Android开源项目到JCenter

登录

使用bintray-release发布

使用github帐号登录https://bintray.com/
你可以点击Your Profile->Edit->API Key,复制。

AS

在最顶层的gradle中添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
buildscript {
repositories {...}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.novoda:bintray-release:0.3.4'//添加
}
}
allprojects {
repositories {...}
tasks.withType(Javadoc) {//添加
options{ encoding "UTF-8" charSet 'UTF-8' links "http://docs.oracle.com/javase/7/docs/api"
}
}
}

在想要上传的module添加

1
2
3
4
5
6
7
8
9
10
11
12
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'//添加
android {...}
dependencies {...}
publish {
userOrg = 'ahaochan'
groupId = 'com.ahaochan'
artifactId = 'TabLayout'//项目名
publishVersion = '0.0.2'//版本号
desc = 'Imitate WeChat6.0 TabLayout'//描述
website = 'https://github.com/Ahaochan/TabLayout'//github地址
}

最后在AS底下的Terminal中输入

1
2
3
4
gradlew clean build bintrayUpload 
-PbintrayUser=ahaochan
-PbintrayKey=之前复制的key
-PdryRun=false