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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容