1.什么是jcenter()
jcenter()是由bintray.com維護(hù)的maven倉(cāng)庫砰碴。
2.為什么選擇jcenter()
jcenter()現(xiàn)在已經(jīng)是android studio 默認(rèn)的代碼倉(cāng)庫猎塞,可以有效減少用戶的操作。
buildscript {
repositories {
google()
jcenter()//這里,這里芝囤,看這里
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
3.注冊(cè)賬號(hào)
注意:部分郵箱驗(yàn)證不通過或者收不到郵件,親測(cè)QQ郵箱不行送丰,搜狐郵箱可以怒详,其他郵箱大家可以嘗試下。
4.創(chuàng)建Maven倉(cāng)庫
5.在對(duì)應(yīng)倉(cāng)庫中創(chuàng)建一個(gè)包
6.創(chuàng)建一個(gè)Android Library (可選擇略過)
1.創(chuàng)建Android Library
2.添加依賴
3.增加測(cè)試代碼
4.測(cè)試引用
7.配置build.gradle
為了方便烙懦,我們使用 bintray-release 來上傳驱入,根據(jù)github上面說明,一步步配置氯析。
1.配置classpath亏较,在最外層的build.gradle中
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.novoda:bintray-release:0.8.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
2.配置publish,在library的build.gradle中
apply plugin: 'com.novoda.bintray-release'
publish {
repoName = 'test'//遠(yuǎn)程倉(cāng)庫名字,不指明掩缓,默認(rèn)是上傳到maven
userOrg = '***'//bintray.com的用戶名
groupId = 'com.test'//jcenter上的路徑
artifactId = 'testlibrary'//項(xiàng)目名稱
publishVersion = '0.0.1'//版本號(hào)
desc = 'for test'//描述
// website = "https://github.com/novoda/${rootProject.name}"http://github 地址
}
8.運(yùn)行下試試
以上從github上拷貝雪情,其中兩個(gè)參數(shù)是未知的,一個(gè)是PbintrayUser 巡通,還有個(gè)是PbintrayKey。PbintrayUser就是用戶名表悬,PbintrayKey是api key,在官網(wǎng)上可以獲取到温治。
publish中用戶名那里把***換成真實(shí)的用戶名。
9.Add to jcenter
10.測(cè)試
完美打印包中的日志,測(cè)試成功冠息。
11.遇到的坑
- HTTP/1.1 400 Bad Request
* What went wrong:
Execution failed for task ':mylibrary:bintrayUpload'.
> Could not create package 'theangrybear/test/testlibrary': HTTP/1.1 400 Bad Request [message:Please enter a valid VCS URL for your package.]
解決方案:沒有創(chuàng)建對(duì)應(yīng)的包,也就是缺少上述的第5步。
- 缺少Pom文件镇眷,沒有自動(dòng)生成
關(guān)于將android項(xiàng)目發(fā)布到j(luò)center的最新最全說明 參考問題3
解決方案:
1.生成pom文件
執(zhí)行 ./gradlew clean build 命令
2.上傳
執(zhí)行 ./gradlew bintrayUpload -PbintrayUser=用戶名 -PbintrayKey=Api key -PdryRun=false
不要再clean,防止pom文件被清掉
- 注釋出現(xiàn)編碼等錯(cuò)誤
//添加
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
}
-
使用Bintray 上傳包到Jcenter上報(bào)錯(cuò)
Failed to send a message: The version control 0.0.1 returns 404.