使用Gradle發(fā)布Android arr項目到j(luò)Center

目的

發(fā)布arr(Android library 項目)到j(luò)Center 遠程倉庫,這樣所有人都可以通過Gradle方式引用。選擇jcenter是因為它兼容maven,而且支持更多形式倉庫,android studio最新版本已經(jīng)默認jcenter了。

平臺準備

https://bintray.com/ 上注冊一個賬號。獲取API key。

生成 javaDoc 和 source JARS

Maven Central 和 jCenter都需要上傳項目的javaDoc 和 source JARS。添加插件 android-maven-plugin 用來生成 javaDoc 和 source JARS。通過bintray 上傳需要添加官方插件 gradle-bintray-plugin。在主項目最外層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

通過gradew執(zhí)行這些任務(wù)完成發(fā)布。

gradew javadocJar
gradew sourcesJar
gradew install
gradew bintrayUpload

關(guān)于審核

當bintrayUpload成功之后,在自己的主頁https://bintray.com/openproject/ 右下部分Latest Activity,會看到提交了一個項目。
進入詳情頁,提交審核就可以了。審核時間大概6小時左右。審核通過后,下次更新版本號發(fā)布就無需審核了。

引用

發(fā)布成功后就可以直接引用

dependencies {
        ...
        compile 'com.dataeye.sdk.ga_v1:ga:2.7.5'
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容