Android Studio上傳Library庫到JCenter,并同步到Maven Central

JCenter

1.注冊Bintray帳號

https://bintray.com

2.記錄UserID和API Key

https://bintray.com/profile/edit

獲取UserID和API Key

3.創建工程

工程目錄結構

4.配置項目

修改項目里的build.gradle(注意是項目不是庫),增加以下兩個dependencies:

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'

配置項目

具體參考:https://github.com/venshine/gradle-bintray-upload

5.配置Library

修改Library庫的build.gradle文件,詳情如下:

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 
artifactversion = "1.0.1"

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    resourcePrefix "wx__"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }    
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.code.gson:gson:2.6.1'
    compile 'com.wx.logger:logger:1.0.1'
}

def siteUrl = 'https://github.com/venshine/AndroidCommon'      // Homepage URL of the library
def gitUrl = 'https://github.com/venshine/AndroidCommon.git'   // Git repository URL
group = "com.wx.android.common"        // Maven Group ID for the artifact

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'                // Add your description here                          
                name 'AndroidCommon'                
                description 'Android Common Library'
                url siteUrl                // Set your license
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id 'venshine'
                        name 'venshine'
                        email 'venshine.cn@gmail.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))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

javadoc {
    options {
        encoding "UTF-8"
    }
}

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"        // it is the name that appears in bintray when logged
        name = "AndroidCommon"
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}

具體參考:https://github.com/venshine/gradle-bintray-upload

6.配置UserID和API Key

這兩個值就是第2步記錄下來的值。
打開項目的local.properties文件,加入以下兩句:

bintray.user=your_bintray_user_name
bintray.apikey=your_bintray_api_key

注:這個文件必須忽略掉,切勿上傳到github上去。
具體參考:https://github.com/venshine/gradle-bintray-upload

7.執行命令

./gradlew install
./gradlew bintrayUpload


點擊工具欄中的Sync projects with Gradle files按鈕對項目進行重建,然后可以看到Gradle視圖中的Task中出現了bintrayUpload,雙擊即可將項目上傳到Bintray中。

上傳項目

8.審核

登錄Bintray網站,去自己的倉庫首頁(https://bintray.com/****/maven) ,找到該庫,點擊Add to JCenter按鈕,然后發送消息,等待審核結果,一般幾個小時的時間就會審核通過。以后再更新項目上傳到Bintray就不需要再次審核了。

加入jcenter倉庫

9.使用

審核通過后,我們即可在其他項目中方便引入這個庫。

compile 'com.wx.android.common:common:1.0.4'

Maven Central

1.注冊帳號

https://issues.sonatype.org

2.創建Issue

https://issues.sonatype.org/secure/CreateIssue!default.jspa
Summary:填寫名稱
Description:填寫描述
Group Id:域名反轉(有效域名),如果沒有域名,可以直接使用自己的github反轉(如github.com/venshine反轉后是com.github.venshine,其中venshine是你的github用戶名。為了規范化,建議全小寫。)
Project URL:項目的url,可以是項目的github地址
其他的條目可以不填,然后提交審核即可,一般2天以內即可審核通過。(審核通過前,你的倉庫是無法使用的)

創建Issue

3.創建 GPG 簽名

安裝GPG生成工具,然后按照下面的步驟操作:

創建 GPG 簽名

注:創建的GPG證書密碼一定保存好

4.配置GPG

打開項目的local.properties文件,加入以下三句:

bintray.gpg.password=your_pgp_password
bintray.oss.user=your_maven_central_user_name
bintray.oss.password=your_maven_central_password

具體參考:https://github.com/venshine/gradle-bintray-upload

5.執行命令

./gradlew install
./gradlew bintrayUpload

6.發布到Maven Central

發布到Maven Central

項目主頁:https://github.com/venshine/gradle-bintray-upload

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,763評論 6 539
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,238評論 3 428
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 177,823評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,604評論 1 317
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,339評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,713評論 1 328
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,712評論 3 445
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,893評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,448評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,201評論 3 357
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,397評論 1 372
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,944評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,631評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,033評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,321評論 1 293
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,128評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,347評論 2 377

推薦閱讀更多精彩內容