android開源庫發布到jcenter圖文詳解與填坑

來源:互聯網
上載者:User

標籤:

相信很多人都用過開源項目,特別是android studio普及以後,使用開源庫更方便簡單。而如何上傳開源庫到jcenter供大家方便使用,雖然網上也有教程,但還是遇坑了,最後總結一下,希望可以協助大家。

【csdn地址: http://blog.csdn.net/zhangke3016/article/details/52075159】
【本文簡書地址: http://www.jianshu.com/p/0acf9e05b27e】同步更新

AndroidStudio是從Maven Repository 伺服器下載類庫的。基本上有jcenterMaven Central這兩個伺服器用於下載Android的類庫。
在代碼裡配置如下: jcenter倉庫

    allprojects {             repositories {                 jcenter()           }    }

Maven Central倉庫:

 allprojects {             repositories {                 mavenCentral()           }    }

首先我們看看寫的gradle代碼的含義:

compile ‘com.mrzk.loadingview:circleloadinglibrary:1.1.0‘

其組成是這樣的:

GROUP_ID:ARTIFACT_ID:VERSION

GROUP_ID指的是com.mrzk.loadingview,類似於包名;ARTIFACT_ID指的是circleloadinglibrary,類似於類庫的名稱;VERSION是1.1.0,也就是版本號碼。

1、在bintray.com上面註冊一個帳號,然後登入進去。

2、註冊登入完成之後,建立倉庫

3、建立倉庫

4、Add New Package

5、選擇要上傳的AndroidStudio項目

6、設定bintray的username和API Key來進行bintray的加密認證

將這些資訊寫在local.properties檔案裡。寫在local.properties的原因在於,bintray的username和APIKey是敏感的私人資訊,應該保管好而不是把它上傳到github上,正好把local.properties檔案寫在.gitignore裡面過濾掉,不會影響上傳的github項目。

如下:

bintray.user=YOUR_BINTRAY_USERNAMEbintray.apikey=YOUR_BINTRAY_API_KEY

username就是你bintray帳號的使用者名稱
apikey在這裡尋找:

7、配置庫module的build.gradle檔案

ext {    bintrayRepo = ‘maven‘    bintrayName = ‘circleloadinglibrary‘    publishedGroupId = ‘com.mrzk.loadingview‘    libraryName = ‘circleloadinglibrary‘    artifact = ‘circleloadinglibrary‘    libraryDescription = ‘a circle loading for android‘    siteUrl = ‘https://github.com/zhangke3016/CircleLoading‘    gitUrl = ‘https://github.com/zhangke3016/CircleLoading.git‘    libraryVersion = ‘1.1.0‘    developerId = ‘mrzk‘    developerName = ‘zhangke‘    developerEmail = ‘609975727@qq.com‘    licenseName = ‘The Apache Software License, Version 2.0‘    licenseUrl = ‘http://www.apache.org/licenses/LICENSE-2.0.txt‘    allLicenses = ["Apache-2.0"]}

我們引用該類庫的代碼就是:

compile ‘com.mrzk.loadingview:circleloadinglibrary:1.1.0‘

8、配置bintray upload的相關代碼
build.gradle檔案的最末行添加下面兩行代碼:

apply from: ‘https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle‘apply from: ‘https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle‘

9、整個project的build.gradle裡面添加最後三行代碼

 dependencies {        classpath ‘com.android.tools.build:gradle:2.0.0‘        classpath ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6‘        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"        classpath ‘com.github.dcendents:android-maven-gradle-plugin:1.3‘    }

10、在AndroidStudio提供的Terminal視窗執行如下命令

gradlew install

順利的話之後會出現:

BUILD SUCCESSFUL

接下來需要把build成功的檔案upload到bintray上:

gradlew bintrayUpload

一切順利之後也會出現:

BUILD SUCCESSFUL

注意,這裡有坑。我在build過程中,出現javadoc產生失敗的問題,在產生javadoc時有檢查文檔的正確性,但是這裡的檢查有點過於嚴格了,像
這種的注釋都會導致產生失敗,而且由於使用的是Windows系統,預設編碼是GBK,所以在上傳編譯時間報了編碼的錯誤問題。
解決方案:
在庫項目的build.gradle裡添加:

allprojects {    tasks.withType(Javadoc) {        options.addStringOption(‘Xdoclint:none‘, ‘-quiet‘)        options.addStringOption(‘encoding‘, ‘UTF-8‘)    }}

11、同步library檔案到建立的bintray倉庫

點擊右下角的Add to JCenter按鈕

跳到一個Request to include the package ‘test’ in ‘jcenter’的頁面,什麼都不用做,直接點擊Send按鈕就可以了。

大概1個小時左右,jcenter審核通過就會在bintray上收到同意訊息提醒。 恭喜你,你的類庫上傳到jcenter成功了!

至此大家用我寫的類庫circleloading,僅僅只需要添加一行代碼:

compile ‘com.mrzk.loadingview:circleloadinglibrary:1.1.0‘

最後,
CircleLoading介紹就在我上一篇部落格中,開源地址:CircleLoading

android開源庫發布到jcenter圖文詳解與填坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.