1.注册 Bintray
注册时要注意哦,千万不要注册成组织的账户,一定要注册为个人。因为组织账户只有一个月的免费使用时间。 个人账户注册地址:bintray.com/signup/oss 有Github、Google、Twitter账号的可以直接登录哦
2.创建Maven仓库(仓库名可自定义)
个人首页中点击Add New Repository,仓库名必须为:maven ,否则使用命令行提交时会报错
3.配置项目
在项目的build.gradle中配置如下:
buildscript {ext.kotlin_version = '1.2.51'repositories {google()jcenter()}dependencies {classpath 'com.android.tools.build:gradle:3.1.3'classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"classpath 'com.novoda:bintray-release:0.8.1'//AS3.0以上版本使用时com.novoda:bintray-release使用最新版本// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files}
}allprojects {repositories {google()jcenter()}gradle.projectsEvaluated {tasks.withType(JavaCompile) {options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"}}
}task clean(type: Delete) {delete rootProject.buildDir
}
//依赖中有中文注释,防止乱码
allprojects {tasks.withType(Javadoc) {options {encoding "UTF-8"charSet 'UTF-8'links "http://docs.oracle.com/javase/7/docs/api"}}
}
//含有kotlin类时需要添加
tasks.getByPath(":${library依赖名}:releaseAndroidJavadocs").enabled = false
复制代码
注意: bintray-release对应的Gradle版本:
bintray-releas version 0.8.0+ 对应 Gradle 是 version 4.1+ (包括4.1)(4.5 不适用)
bintray-releas version 0.7.0 对应 Gradle 是 version 4.1+ (包括4.1)
bintray-releas version 0.6.1 对应 Gradle 是 version 4.1+ (包括4.1)
bintray-releas version 0.5.0 对应 Gradle 是 version 3.4+ (包括3.4)
bintray-releas version 0.4.0 对应 Gradle 是 version 3.3+ (包括3.3)
bintray-releas version 0.3.4 对应 Gradle 是 version 1.3.0+(包括1.3)
复制代码
要发布的 module 下的 build.gradle 中添加如下配置:
apply plugin: 'com.novoda.bintray-release'//添加
publish {repoName="maven"//仓库名,没有填写时默认仓库是mavenuserOrg = 'lsmya'//bintray.com用户名groupId = 'cn.lsmya.**'//jcenter上的路径artifactId = '***'//项目名称publishVersion = '1.0.1'//版本号desc = 'Android rapid development framework'//描述website = 'https://github.com/lsmya/fastFrame'//github上的地址
}
复制代码
apikey的获取:
完成三个地方的配置后,就可以通过命令把项目上传到 Bintray 了。
4.上传项目到Bintray
在Android Studio的终端(Terminal)中使用命令行: Win请使用:
gradlew clean build bintrayUpload -PbintrayUser=${your_username} -PbintrayKey=${your_apikey} -PdryRun=false
复制代码
Mac请使用:
./gradlew clean build bintrayUpload -PbintrayUser=${your_username} -PbintrayKey=${your_apikey} -PdryRun=false
复制代码
PbintrayUser:登录binary网站的用户名。 PbintrayKey:上面提到的apikey。 dryRun:一个配置参数,当为true的时候,会进行所有步骤,但是不会上传到binary。
回车之后等待编译打包,出现 BUILD SUCCESS,则表示上传成功。 回到Bintray的首页点击之前创建的Maven仓库就可以看到上传的library了
5.将项目发布到JCenter
点击Add to JCenter,在新页面中点击Send,之后就等待Bintrary的审核吧,如果审核通过会以邮件通知你。