Android項目實戰(三十八):2017最新 將AndroidLibrary提交到JCenter倉庫(圖文教程)

來源:互聯網
上載者:User

標籤:pid   repo   include   結構   lin   tools   ref   oid   bestcode   

原文:Android項目實戰(三十八):2017最新 將AndroidLibrary提交到JCenter倉庫(圖文教程)

我們經常使用github上的開源項目,使用步驟也很簡單

比如:

compile ‘acffo.xqx.xwaveviewlib:maven:1.0.0‘

這裡就學習一下如何將自己的類庫做出這種可以供他人使用的開源項目。

 

一、Android studio項目準備

 

  這時候我們想寫了一個自訂控制項,想要傳到github上讓別人使用。

  1、先在該項目下建立一個Module

   

  2、選擇Android Library

   

    3、填寫類庫名稱

  

  4、此時的目錄結構

  

  注意,開源出去的是library類庫,所以需要在類庫中寫自訂控制項或者其他代碼,而不是在app目錄下

 

  5、建立一個自訂控制項View

  

  

  6、在app目錄下 寫使用該類庫的相關範例程式碼 ,讓app依賴該類庫

  

 

  

  二、Bintray準備

  1、首先建立一個Bintray帳號,登入位址 https://bintray.com/signup/oss 注意這是個人帳號註冊,很多文章給的連結是公司帳號註冊。

     有個注意點:郵箱不能是163的 也許還有別的也不能使用,建議使用Google的gmail郵箱。

  

  2、建立找好成功之後,選擇建立組織

  

  可以看到已經建立好的組織

  

  3、選擇進入一個,比如我進入xqxlibrary組織 ,然後介面如下,再繼續點擊建立倉庫

  

  

   4、建立倉庫介面如下

  

   建立完成之後可以看到xqxlibrary組織下多了一個倉庫

  

 

   5、最後我們要記錄一下自己的Bintray使用者名稱 和 API Key 值,Android studio配置的時候需要

   

    

    複製API Key

 

 三、Android Studio 項目 配置

  1、根目錄下的build.gradle 配置

  在 dependencies{} 中添加

        classpath ‘com.novoda:bintray-release:0.3.4‘

  在allprojects中添加:

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

 

最終如下:

buildscript {
repositories {
jcenter()
}
dependencies {
classpath ‘com.android.tools.build:gradle:2.2.2‘
classpath ‘com.novoda:bintray-release:0.3.4‘
}
}

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

  2、module目錄下的build.gradle 配置

  (1)、最頂端添加代碼

apply plugin: ‘maven‘apply plugin: ‘com.novoda.bintray-release‘

  (2)、Bintray配置資料區

//添加publish {    userOrg = ‘xqxlibrary‘        // 組織名    groupId = ‘acffo.xqx.mycustomview‘  //類庫的包名    artifactId = ‘maven‘       // 工程名 ,自訂                     publishVersion = ‘1.0.0‘         //版本號碼    desc = ‘波浪流動效果‘ //描述     website = ‘https://github.com/BestCoderXQX/XWaveView‘ //github地址  你可以把你的項目push到你的github上 , 項目的地址即這個地址}

  全部代碼:

apply plugin: ‘com.android.library‘apply plugin:  ‘maven‘apply plugin: ‘com.novoda.bintray-release‘android {    compileSdkVersion 25    buildToolsVersion "25.0.3"    defaultConfig {        minSdkVersion 15        targetSdkVersion 25        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘        }    }}dependencies {    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])    androidTestCompile(‘com.android.support.test.espresso:espresso-core:2.2.2‘, {        exclude group: ‘com.android.support‘, module: ‘support-annotations‘    })    compile ‘com.android.support:appcompat-v7:25.3.1‘    testCompile ‘junit:junit:4.12‘}//添加publish {    userOrg = ‘xqxlibrary‘    groupId = ‘acffo.xqx.xwaveviewlib‘    artifactId = ‘maven‘    publishVersion = ‘1.0.0‘    desc = ‘波浪流動效果‘    website = ‘https://github.com/BestCoderXQX/XWaveView‘}
View Code

 

  四、執行Gradlew命令語句

gradlew clean build bintrayUpload -PbintrayUser=a463674420 -PbintrayKey=6f5e4e11d2d253a2d4************** -PdryRun=false

  解釋如下:

gradlew clean build bintrayUpload -PbintrayUser=a463674420 (這裡是網站頭像旁邊對應的帳號,有可能跟網址上面的不一樣,一定要區分好)-PbintrayKey=6f5e4e11d2d253a2d4************** (這個是上面讓大家複製儲存下來的API key)-PdryRun=false(如果是false那麼就會真實提交,如果是true不會去進行真實提交,但是會編譯,可以去查看是否編譯通過在提交)

   執行到SUCCESSFUL 即表示成功了。

 

    

  五、提交審核

  找到建的組織下的倉庫 , 會發現 多了一個package

  

   點擊進入 ,點擊右側的"Add to JCenter"即可提交審核 ,用的時候點擊左下側的‘Gradle‘即可

   

 

   

Android項目實戰(三十八):2017最新 將AndroidLibrary提交到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.