首先我們看看寫的gradle代碼的含義:
compile 'com.first:FirstLibrary:1.0.0'
- 1
其組成是這樣的:
GROUP_ID:ARTIFACT_ID:VERSION
GROUP_ID指的是com.first,類似於包名;ARTIFACT_ID指的是FirstLibrary,類似於類庫的名稱;VERSION是1.0.0,也就是版本號。
- 註冊賬號
在bintray.com上面註冊一個賬號,然後登錄進去。
註冊登錄地址:https://bintray.com/login?forwardedFrom=%2Flogin
- 登進來之後創建倉庫
- 創建一個package,點擊剛纔創建的MyMaven,進去後點擊右下角的Add New Package
截止到現在 Bintrary上面環境已經完成了,下面說下如何將一個項目中的庫文件上傳到jcenter上
- 創建一個新的項目,然後創建一個model,這個就不詳細描述了,如下圖所示,咱們的目的是將firstlibrary上傳到jcenter
- 配置項目的根gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.novoda:bintray-release:0.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 配置庫(項目中的Model—firstlibrary的)gradle,這個地方一定不要配置到項目的gradle下,
apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'
publish {
repoName = 'MyMaven'//遠程倉庫名字,不指明,默認是上傳到maven
userOrg = 'developwb'//bintray.com用戶名
groupId = 'com.first'//jcenter上的路徑,bintray上創建Package時填寫的Version control項
artifactId = 'FirstLibrary'//項目名稱,bintray上創建Package時填寫的Name項
publishVersion = '1.0.0'//版本號
desc = '描述'//描述,不重要
website = '111'//網站,最好有,不重要
}
android {
compileSdkVersion 26
defaultConfig {
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 在終端輸入如下命令
gradlew clean build bintrayUpload -PbintrayUser=developwb -PbintrayKey=********************* -PdryRun=false
其中PbintrayUser 是你的bintray賬戶名字 PbintrayKey我們需要到bintrary裏面找,如下圖
現在PbintrayUser和PbintrayKey我們都知道了,放到上面的命令中,對號入座,然後點擊回車。。。坐等上傳成功
看到下圖中的successful就表示上傳成功了。
- 提交到jcenter
·這時候我們需要在下面填寫審覈描述(亂填都行不能不填,不填可能會審覈失敗!)(如下圖↓↓↓)
·填寫完成直接Send,一般一天之後就會審覈通過,通過後項目的右下角的Add to JCenter 按鈕就會消失!
審覈通過後就可以引用了
compile 'com.first:FirstLibrary:1.0.0'
- 1
- 上傳常見錯誤
·下面我們來看看上傳過程中的常見錯誤(如果你成功了可以不用看下面):
(1).HTTP/1.1 404 Not Found [message:Repo ‘MyMaven’ was not found]
找不到Maven庫,可能是你沒有創建,或者是你repoName的值跟你創建的倉庫名字不一樣,還有可能是你的userOrg也沒有寫對!
(2).HTTP/1.1 400 Bad Request [message:Please enter a valid VCS URL for your OSS package.]
找不到包,在對應的Maven庫下沒有創建對應的包,或者是你artifactId的值跟你創建的包名字不一樣!
第三個坑:Execution failed for task ':core:lint'.
Execution failed for task ':core:lint'.
> Lint found errors in the project; aborting build.
在上傳過程中執行了lint檢查,所以可能會報上面的錯誤。解決方法就是避免lint的檢查,在每個module的gradle下面就要添加如下配置:
android {
lintOptions {
abortOnError false
}
}
第四個坑:Execution failed for task ':core:mavenAndroidJavadocs'.
Execution failed for task ':core:mavenAndroidJavadocs'.
> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '/Users/zhou/git/app/core/build/tmp/mavenAndroidJavadocs/javadoc.options'
在上傳過程中執行了javadoc檢查,所以可能會報上面的錯誤。解決方法就是避免javadoc的檢查,在項目根目錄下的gradle下面就要添加如下配置:
allprojects {
repositories {
jcenter()
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
}
}
作者:王宗耀 歡迎轉載,與人分享是進步的源泉!
轉載請保留原文地址:http://blog.csdn.net/wzy901213