目的
發(fā)布arr(Android library 項(xiàng)目)到j(luò)Center 遠(yuǎn)程倉(cāng)庫(kù)映跟,這樣所有人都可以通過(guò)Gradle方式引用壹甥。選擇jcenter是因?yàn)樗嫒輒aven蛙粘,而且支持更多形式倉(cāng)庫(kù)艰猬,android studio最新版本已經(jīng)默認(rèn)jcenter了聪富。
平臺(tái)準(zhǔn)備
在 https://bintray.com/ 上注冊(cè)一個(gè)賬號(hào),獲取API key愕宋。
生成 javaDoc 和 source JARS
Maven Central 和 jCenter都需要上傳項(xiàng)目的javaDoc 和 source JARS玻靡。添加插件 android-maven-plugin 用來(lái)生成 javaDoc 和 source JARS。通過(guò)bintray 上傳需要添加官方插件 gradle-bintray-plugin中贝。在主項(xiàng)目最外層build.gradle 文件 buildscript/dependencies中添加插件囤捻。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath 'net.sf.proguard:proguard-gradle:4.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
在需要發(fā)布的app Module的build.gradle 文件中添加 生成javadoc和source jar的tasks等。下面的以游戲分析1.0 為例子邻寿。
apply plugin: 'com.android.library'
//需要的插件
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
// This is the library version used when deploying the artifact
version = "2.7.5"
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 11
targetSdkVersion 22
versionCode 275
versionName "2.7.5"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'pro_DataEye_Android_2.7.1_100271000.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
}
//定義 group
group = "com.dataeye.sdk.ga_v1"
def siteUrl = 'https://github.com/DataEye' // project homepage
def gitUrl = 'https://github.com/DataEye' // project git
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
name 'GASdk_V1'
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 'cristianohao'
name 'cristianohao'
email 'gonghao@dataeye.com'
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
javadoc {
options{
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "maven"
name = "GASdk_V1" // project name in jcenter
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
本地 local.properties 添加API key
bintray.user=deandroid // your bintray user name
bintray.apikey=358f11719ba4289156e6195a7e6753584258f6f3 // your bintray api key
通過(guò)gradew執(zhí)行這些任務(wù)完成發(fā)布蝎土。
gradlew javadocJar
gradlew sourcesJar
gradlew install
gradlew bintrayUpload
關(guān)于審核
當(dāng)bintrayUpload成功之后,在自己的主頁(yè)https://bintray.com/openproject/右下部分Latest Activity绣否,會(huì)看到提交了一個(gè)項(xiàng)目誊涯。
進(jìn)入詳情頁(yè),提交審核就可以了蒜撮。審核時(shí)間大概6小時(shí)左右暴构。審核通過(guò)后,下次更新版本號(hào)發(fā)布就無(wú)需審核了。
引用
發(fā)布成功后就可以直接引用
dependencies {
...
compile 'com.dataeye.sdk.ga_v1:ga:2.7.5'
}