[TOC]
創建 Jcenter 賬號
提供官網注冊賬號地址:官網
-
注冊賬號,這里有一個容易忽略的坑:注冊賬號的時候,大家肯定是會被很明顯的位置吸引,但是,很不幸的告訴你,如果這一步就做錯了,下面的內容不用看了;
@注冊賬號 | center |
圖中的兩種注冊賬戶:
- 普通賬戶
-
Open source plan (開源) 賬戶
而我們想要將Libray開放處理,則必須使用第二種注冊賬戶方式;
@賬號登陸 | center |
獲取API-Key
@獲取appkey | center |
@獲取appkey | center |
通過圖中所示方式,獲取 API-key,保存起來,后續上傳時會用到
倉庫的創建
@創建倉庫 | center |
@命名要求 | center |
如圖示:
命名時需要注意:由于是通過
bintray-release
插件上傳到 jcenter
,其命名必須為:maven
,不讓上傳時會提示:HTTP/1.1 404 Not Found [message:Repo ‘maven’ was not found]
項目中配置
項目引入 bintray—release 插件
在項目的 build.gradle 文件中增加如下配置
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// 增加下面一行代碼
classpath 'com.novoda:bintray-release:0.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
目前 bintray-relase 插件 更新到了 0.4.0 版本
LibrayrModule 中 build.gradle 中配置
apply plugin: 'com.android.library'
// 增加
apply plugin: 'com.novoda.bintray-release'
android {
...
}
dependencies {
...
}
// 增加
publish {
userOrg = 'qazxsw' // bintray.com用戶名
groupId = 'com.qazxsw' // jcenter上的路徑
artifactId = 'basetools' // 項目名稱
publishVersion = '1.0.0' // 版本號
desc = 'Oh hi, this is a nice description for a project, right?'//描述,不重要
website = 'https://github.com/username/projectname'// 項目的地址,一般情況下是 github 上的開源項目(oschina...等也可)
}
如果你已經執行到了這一步,恭喜你,已經快了,再前行一步就到為了...
Library 的編譯上傳
在 Android Studio 的 Terminal 窗口 內執行
windows:
gradlew clean build bintrayUpload
-PbintrayUser=用戶名
-PbintrayKey=API-key
-PdryRun=false
---- 華麗的分隔線 -----
linux:
./gradlew clean build bintrayUpload
-PbintrayUser=用戶名
-PbintrayKey=API-key
-PdryRun=false
其中
PbintrayUser 使用你的 Bintray 的用戶名
PbintrayKey 使用你的 Bintray 的Api-key (上面已經獲取到了)
當運行完成,看到BUILD SUCCESSFUL就OK了;
如果你以為到這里就ok了,那就萌萌噠了...
提交審核
你可以通過直接輸入 https://bintray.com/用戶名/maven 可以打開倉庫,可以看到你剛剛提交的 Librayr以及你定義的版本號
@倉庫中Library信息 | center |
@倉庫中Library信息 | center |
打開 Library 點擊 AddToJcenter 按鈕,慢慢等待審核,如果通過了審核,恭喜各位看官,已經可以在項目中愉快的使用你的 Library 了;
總結
主要分為幾個步驟
- 申請賬號(注意賬號類型)--- 很重要,是基礎
- 引入 bintrary-release 插件,填寫相關配置信息
- 上傳命令提交到 Bintrary 上的倉庫
- 提交到 Jcenter 審核
感謝:
Android 快速發布開源項目到jcenter
利用bintray-release插件上傳到jcenter
利用bintray-release插件上傳到Bintray- HTTP/1.1 404 Not Found [message:Repo 'maven' was not found]問題解決