1. Bintray账号
Bintray网站 https://bintray.com/(需要翻墙)
1.1 先注册账号(傻瓜式,非职业选手也能搞定)
1.2 然后登陆账号
1.3 点击your profile

1.4 点击Edit

1.5 点击API Key

1.6 将key复制下来保存,后边要用,然后回到网站首页

1.7 点击Add,建立仓库

1.8 填写信息,type选maven,其他随便写,然后create,之后会自己调到仓库页面

1.9 点击Add New Package创建Package

1.10 填写内容,带*为必填项,点击Create Package

1.11 点开Package后页面如下就ok了

2. 发布前配置信息
2.1 在项目根目录的 local.properties 文件中添加 Bintray 的账号信息:
bintray.user=用户名
bintray.apikey=第一步获取到的API key
2.2 在Project的build.gradle配置插件依赖
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
}
}
这里要说一下遇到的坑,原来'com.github.dcendents:android-maven-gradle-plugin:1.4.1'写的是1.3
执行的时候出现 Noservice of type Factory available in ProjectScopeServices
在这里找到解决办法,貌似是AS版本问题
2.3 在model的build.gradle配置
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
version = "0.0.4"
group = "com.peipei.ptool"
def siteUrl = 'https://github.com/yadav-rahul/TastyToast'
def gitUrl = 'https://github.com/yadav-rahul/TastyToast.git'
//compile 'com.facebook.rebound:rebound:0.3.8'
//这里的version就是上边rebound后边的版本号
//group就是com.facebook.rebound
//siteUrl 项目主页
//gitUrl 项目的git地址
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 24
versionCode 4
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.facebook.rebound:rebound:0.3.8
}
install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'// 打包的类型
name 'ptool'//项目名称
description '描述'// 项目的描述
url siteUrl// 项目的主页
// 配置开源证书信息
licenses {
license {
name 'The Apache software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
// 配置开发者信息
developers {
developer {
id ''
name 'peipei'
email '****@gmail.com'
}
}
// 软件配置管理信息
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
//生成对应的source.jar
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
//生成java doc文件
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
failOnError false
// 忽略注释语法错误,如果用jdk1.8你的注释写的不规范就编译不过。
}
//生成对应的javadoc.jar
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
// 读取配置的bintray用户的信息
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
// 配置bintray的信息
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "***"//在bintray上边建立的仓库名字
name = "****"//在bintray上Package名字
websiteUrl = siteUrl
vcsUrl = gitUrl
labels = ['android'] // 设置标签
licenses = ["Apache-2.0"]
publish = true
}
}
//javadoc生成的时候使用GBK编码,而项目使用的UTF-8编码。就需要加入以下代码
javadoc {
options{
encoding 'UTF-8'
charSet 'UTF-8'
author true
}
}
配置完成后调用 Gradle 命令上传即可:
Terminal 输入 gradlew bintrayUpload
3. 同步到JCenter

点击Add to JCenter,等审核通过就可以用了

在Package页面可以找到 compile 'com.peipei.ptool:ptool:1.0.0'

这样就将library传到了JCenter
4. 可能的坑
-
HTTP/1.1 409 Conflict
版本存在 -
java.net.SocketException: Software caused connection abort: socket write error
翻墙吧
推荐一个比较简单的方法【Android】5分钟发布Android Library项目到JCenter 使用的是android-library-publish-to-jcenter,android-library-publish-to-jcenter已经将需要写的脚本封装好了,我们只需要配置相关属性即可在5分钟之内发布我们的项目到JCenter(不包括审核时间哦)
网友评论