Android Studio發(fā)布項(xiàng)目到Jcenter倉庫步驟(圖文)
前言:Android Studio中把項(xiàng)目的lib庫提交到Jcenter倉庫中,需要使用到Bintray,Bintray是jCenter的提供商,他支持上傳lib到多個(gè)平臺(tái),jCenter只是眾多平臺(tái)中的一個(gè),形象的說jCenter是位于某地的倉庫,Bintray是送貨的卡車,你寫的庫就是貨了。
第一部分:在Bintray上注冊(cè)賬號(hào),并創(chuàng)建package。
注冊(cè)bintray ,注意:注冊(cè)時(shí)盡量使用國外的郵箱,避免接收不到驗(yàn)證碼。例如我使用雅虎郵箱。
完成注冊(cè)之后,登錄網(wǎng)站,然后點(diǎn)擊maven。

點(diǎn)擊Add New Package,為我們的library創(chuàng)建一個(gè)新的package。

假設(shè)你已經(jīng)注冊(cè)賬你并按照上面步驟操作,或者使用我提供的賬號(hào),登陸成功后會(huì)出現(xiàn)如下界面,點(diǎn)擊maven進(jìn)入該倉庫,并點(diǎn)擊Add New Package創(chuàng)建新的包。

填寫package相關(guān)信息,如下:

第二部分:操作AS項(xiàng)目,配置相關(guān)信息,命令行操作lib包上傳。
Android Studio安裝上傳Bintray插件和填寫相關(guān)信息:(下面選用我測(cè)試通過并且操作路徑最短的方式)
在項(xiàng)目的根build文件中補(bǔ)充如下標(biāo)紅內(nèi)容
這是根build源文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.novoda:bintray-release:+' // 新增
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
tasks.withType(Javadoc) { // 新增
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
然后在lib的build文件中補(bǔ)充如下內(nèi)容:
這是lib的源build文件:
`apply plugin: ``'com.android.library'`
`apply plugin: ``'com.novoda.bintray-release'` `// 新增`
`android {`
`compileSdkVersion ``28`
`defaultConfig {`
`minSdkVersion ``15`
`targetSdkVersion ``28`
`versionCode ``2`
`versionName ``"1.0.2"`
`testInstrumentationRunner ``"android.support.test.runner.AndroidJUnitRunner"`
`}`
`buildTypes {`
`release {`
`minifyEnabled ``false`
`proguardFiles getDefaultProguardFile(``'proguard-android.txt'``), ``'proguard-rules.pro'`
`}`
`}`
`lintOptions { ``// 新增`
`abortOnError ``false`
`}`
`}`
`dependencies {`
`implementation fileTree(dir: ``'libs'``, include: [``'*.jar'``])`
`implementation ``'com.android.support:appcompat-v7:28.0.0-rc02'`
`testImplementation ``'junit:junit:4.12'`
`androidTestImplementation ``'com.android.support.test:runner:1.0.2'`
`androidTestImplementation ``'com.android.support.test.espresso:espresso-core:3.0.2'`
`}`
`publish { ``// 新增`
`userOrg = ``'huangweicai'` `// 注冊(cè)bintray時(shí)的username`
`groupId = ``'com.infinitus_demo_lib'` `// 項(xiàng)目包名`
`artifactId = ``'infinitus_demo_lib'` `// 項(xiàng)目名`
`publishVersion = ``'1.0.2'` `// 發(fā)布版本號(hào)`
`desc = ``'Summarize the tools or methods commonly used in routine development'` `// 項(xiàng)目描述,可選項(xiàng)`
`website = ``'[https://github.com/huangweicai/infinitus_demo_lib'](https://github.com/huangweicai/infinitus_demo_lib')` `// 項(xiàng)目站點(diǎn),可選項(xiàng)`
`}`
在Android Studio的命令行窗口依次輸入如下命令:
gradlew generatePomFileForReleasePublication gradlew publishReleasePublicationToMavenLocal gradlew bintrayUpload -PbintrayUser=xxx -PbintrayKey=xxx -PdryRun=false
其中,PbintrayUser是Bintray的用戶名,PbintrayKey是Bintray的API Key。(API Key在注冊(cè)成功后,可以在修改信息的界面找到,最好在第一次注冊(cè)成功后就記錄好)

等待執(zhí)行,看到BUILD SUCCESSFUL說明上傳Bintray成功。
進(jìn)入Bintray,可以找到我們上傳的包,在頁面的左下角看到maven地址說明上傳內(nèi)容正確,第一次在頁面的右下角會(huì)看到add to jcenter,需要我們手動(dòng)點(diǎn)擊一下這個(gè)add to jcenter按鈕,然后等待lib包審核通過后,我們就可以引用jcenter上的包了。
以上就是Android Studio打包上傳到Jcenter的完整流程。
測(cè)試:AS引入implementation ‘com.infinitus_demo_lib:infinitus_demo_lib:1.0.2',代碼中調(diào)用演示工具類TestUtil.test(context);查看吐司是否提示,提示成功說明已經(jīng)成功發(fā)布并引入jcenter包。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android發(fā)布項(xiàng)目到j(luò)itpack的完整步驟
- 詳解androidstudio項(xiàng)目上傳到github方法以及步驟
- Android studio刪除Android項(xiàng)目方法
- Android開發(fā)導(dǎo)入項(xiàng)目報(bào)錯(cuò)Ignoring InnerClasses attribute for an anonymous inner class的解決辦法
- 取消Android Studio項(xiàng)目與SVN關(guān)聯(lián)的方法
- Eclipse運(yùn)行android項(xiàng)目報(bào)錯(cuò)Unable to build: the file dx.jar was not loaded from the SDK folder的解決辦法
- 實(shí)例講解建立Android項(xiàng)目
相關(guān)文章
Android 10 啟動(dòng)之servicemanager源碼解析
這篇文章主要為大家介紹了Android 10 啟動(dòng)之servicemanager源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
Android 實(shí)現(xiàn)不依賴焦點(diǎn)和選中的TextView跑馬燈
本文主要介紹Android 跑馬燈的實(shí)現(xiàn),這里提供實(shí)現(xiàn)詳細(xì)實(shí)現(xiàn)代碼供大家參考,有需要的小伙伴可以看下2016-07-07
Android開發(fā)模仿qq視頻通話懸浮按鈕(實(shí)例代碼)
這篇文章主要介紹了Android開發(fā)模仿qq視頻通話懸浮按鈕功能的實(shí)例代碼,需要的的朋友參考下2017-02-02
Android Flutter實(shí)現(xiàn)GIF動(dòng)畫效果的方法詳解
如果我們想對(duì)某個(gè)組件實(shí)現(xiàn)一組動(dòng)效應(yīng)該怎么辦呢?本文將利用Android Flutter實(shí)現(xiàn)GIF動(dòng)畫效果,文中的示例代碼講解詳細(xì),需要的可以參考一下2022-06-06
Flutter利用Canvas模擬實(shí)現(xiàn)微信紅包領(lǐng)取效果
這篇文章主要為大家詳細(xì)介紹了如何利用Flutter中的Canvas模擬實(shí)現(xiàn)微信紅包領(lǐng)取的效果,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2022-03-03

