將自己的安卓開源項目分享到jcenter給大家使用,也是不斷封裝自己所學的東西,方便使用。
一、註冊bintray賬號
1.申請Bintray賬號並獲取所需信息:註冊個人免費版:https://bintray.com/signup/oss
2.使用火狐郵箱foxmail進行Bintray賬號註冊。 (不能用QQ,163等郵箱,Google可以使用,但不方便。)
火狐郵箱申請教程:如何註冊火狐郵箱
二、登錄bintray
點擊頭像處:Edit Profile—>API key,需將API key複製保存下來,爲之後上傳會使用。
注意,需要先輸入登錄密碼。
三、創建倉庫
點擊頭像處:View Profile—>Add New Repository。
填寫信息,其中表單其中Type選Maven
四、創建項目
新建一個Android library,該library寫一些工具類方法,然後將其上傳到jcenter。
1.項目根build.gradle文件引入bintray-release(推送助手)
完整配置:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
//黃油刀
classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'
// 推送到bintray助手
classpath 'com.novoda:bintray-release:0.9.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
// 解決上傳亂碼問題
tasks.withType(Javadoc) {
options {
encoding "UTF-8"
charSet "UTF-8"
links "http://docs.oracle.com/javase/7/docs/api"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
tasks.getByPath(":lgzutil:javadocRelease").enabled = false
2.上傳的moudle下的build.gradle文件添加如下代碼
// 添加以下內容
apply plugin: 'com.novoda.bintray-release'
publish {
userOrg = '***'//bintray.com用戶名
groupId = 'com.zachary'//jcenter上的路徑
artifactId = 'lgzutils'//項目名稱
publishVersion = '1.0.2'//版本號
desc = '安卓工具類,交互優雅的通用彈窗!'//庫的描述,不重要
website = 'https://github.com/LiZachary/lgzUtils'//網站,最好有,不重要
}
最終引用格式爲"implementation" + groupId + ":" + artifactId + ":" + publishVersion 。
五、執行上傳命令
在Android studio的Terminal面板輸入命令上傳,
- 其中PbintrayUser爲用戶名
- PbintrayKey爲第二步得到的API key
- PdryRun爲false
// win下命令
gradlew clean build bintrayUpload -PbintrayUser=*** -PbintrayKey=**** -PdryRun=false
// mac下命令
./gradlew clean build bintrayUpload -PbintrayUser=*** -PbintrayKey=**** -PdryRun=false
六.上傳完成,添加到jcenter倉庫
提交的時候要做一個簡短的英文描述,儘量不要用中文。你需要等待bintray的工作人員審覈,審覈通過會給你發送站內Message,大概兩個小時左右,並且Add to Jcenter那個按鈕就消失了。
七.更新倉庫
以後更新庫只需修改publishVersion重新上傳即可。
問題:
報錯:Bintray- HTTP/1.1 404 Not Found [message:Repo ‘maven’ was not found]
創建倉庫時,如果使用Bintray-release,名字就填成maven,因爲他的wiki:repoName: The repository name. Set to ‘maven’ by default.