[Android]釋出自己的專案庫到jcenter
阿新 • • 發佈:2019-02-11
前言
閒來無聊,看到鴻洋大神的Android 快速釋出開源專案到jcenter,在學習和使用bintray-release釋出一般專案到jcenter的過程中,雖然寫的很清晰,但是我還是fail了。重新查了一下別人的教程,決定也寫個簡單說明,步驟其實差不多的,在此做個記錄。
注:這是上傳一般的單獨的專案到jcenter上!
步驟
先看看我要上傳的專案結構,就是在Android Studio中建立一個專案,再New module->Android Library即可
註冊需要郵箱啟用,啟用成功後,我們再去登入
進入如下網頁介面,Copy出我們一會兒需要用到的API KEY:
二、引入bintray-release
(1).在我的主專案的build.gradle(不是Library的)下新增bintray-release的classpath
/MyLib/build.gradle
(2).接著在Library下的build.gradle下新增bintray-release元件和釋出相關資訊的配置buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' classpath 'com.novoda:bintray-release:0.3.4' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }
/MyLib/crazy-lib/build.gradle
請關注註釋的2處地方即可。
apply plugin: 'com.android.library' apply plugin: 'com.novoda.bintray-release' //新增bintray-release元件,記得一定要....library放在下面 android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { minSdkVersion 15 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { abortOnError false } } //無需關注,本人demo裡的依賴包 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'org.greenrobot:eventbus:3.0.0' compile 'org.greenrobot:greendao:3.2.0' compile 'in.srain.cube:ultra-ptr:1.0.11' } //這是釋出到jcenter上的相關資訊新增 publish { userOrg = 'jans'//bintray.com使用者名稱,不是註冊賬號名 groupId = 'com.jan.lib'//jcenter上的路徑,這裡是我的包名 artifactId = 'exampleLib'//專案名稱 publishVersion = '1.1.2'//你要提交的版本號 desc = 'hi,baby!do not look me!'//描述,不重要 website = 'http://blog.csdn.net/jan_s'//網站,不重要;儘量模擬github上的地址,例如我這樣的;當然你有地址最好了 }
(3).我們回到https://bintray.com/上,找到Add New Repository ,建立一個
好了,接下來我們到專案目錄下,如本demo的MyLib下,執行一串上傳命令(windows環境)即可:
gradlew clean build bintrayUpload -PbintrayUser=你的賬號名 -PbintrayKey=你的API KEY -PdryRun=false
如果看到BUILD SUCCESSFUL 就說明你成功了!
我們去bintray上看看
看到了嗎,這就是單獨上傳一個專案的方式,很簡單吧,然後你點開這個專案,可以看到Gradle的配置寫法,下次你給別人引用的話,只要一行程式碼就夠了
compile 'com.jan.lib:exampleLib:1.1.2'
謝謝,就寫到這裡,有問題請留言。