Android Studio發(fā)布項目到Jcenter倉庫步驟(圖文)
前言:Android Studio中把項目的lib庫提交到Jcenter倉庫中,需要使用到Bintray,Bintray是jCenter的提供商,他支持上傳lib到多個平臺,jCenter只是眾多平臺中的一個,形象的說jCenter是位于某地的倉庫,Bintray是送貨的卡車,你寫的庫就是貨了。
第一部分:在Bintray上注冊賬號,并創(chuàng)建package。
注冊bintray ,注意:注冊時盡量使用國外的郵箱,避免接收不到驗證碼。例如我使用雅虎郵箱。
完成注冊之后,登錄網站,然后點擊maven。
點擊Add New Package,為我們的library創(chuàng)建一個新的package。
假設你已經注冊賬你并按照上面步驟操作,或者使用我提供的賬號,登陸成功后會出現如下界面,點擊maven進入該倉庫,并點擊Add New Package創(chuàng)建新的包。
填寫package相關信息,如下:
第二部分:操作AS項目,配置相關信息,命令行操作lib包上傳。
Android Studio安裝上傳Bintray插件和填寫相關信息:(下面選用我測試通過并且操作路徑最短的方式)
在項目的根build文件中補充如下標紅內容
這是根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文件中補充如下內容:
這是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'` `// 注冊bintray時的username` `groupId = ``'com.infinitus_demo_lib'` `// 項目包名` `artifactId = ``'infinitus_demo_lib'` `// 項目名` `publishVersion = ``'1.0.2'` `// 發(fā)布版本號` `desc = ``'Summarize the tools or methods commonly used in routine development'` `// 項目描述,可選項` `website = ``'[https://github.com/huangweicai/infinitus_demo_lib'](https://github.com/huangweicai/infinitus_demo_lib')` `// 項目站點,可選項` `}`
在Android Studio的命令行窗口依次輸入如下命令:
gradlew generatePomFileForReleasePublication gradlew publishReleasePublicationToMavenLocal gradlew bintrayUpload -PbintrayUser=xxx -PbintrayKey=xxx -PdryRun=false
其中,PbintrayUser是Bintray的用戶名,PbintrayKey是Bintray的API Key。(API Key在注冊成功后,可以在修改信息的界面找到,最好在第一次注冊成功后就記錄好)
等待執(zhí)行,看到BUILD SUCCESSFUL說明上傳Bintray成功。
進入Bintray,可以找到我們上傳的包,在頁面的左下角看到maven地址說明上傳內容正確,第一次在頁面的右下角會看到add to jcenter,需要我們手動點擊一下這個add to jcenter按鈕,然后等待lib包審核通過后,我們就可以引用jcenter上的包了。
以上就是Android Studio打包上傳到Jcenter的完整流程。
測試:AS引入implementation ‘com.infinitus_demo_lib:infinitus_demo_lib:1.0.2',代碼中調用演示工具類TestUtil.test(context);查看吐司是否提示,提示成功說明已經成功發(fā)布并引入jcenter包。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Android發(fā)布項目到jitpack的完整步驟
- 詳解androidstudio項目上傳到github方法以及步驟
- Android studio刪除Android項目方法
- Android開發(fā)導入項目報錯Ignoring InnerClasses attribute for an anonymous inner class的解決辦法
- 取消Android Studio項目與SVN關聯的方法
- Eclipse運行android項目報錯Unable to build: the file dx.jar was not loaded from the SDK folder的解決辦法
- 實例講解建立Android項目
相關文章
Android直播軟件搭建之實現背景顏色滑動漸變效果的詳細代碼
這篇文章主要介紹了Android直播軟件搭建之實現背景顏色滑動漸變效果的詳細代碼,代碼簡單易懂,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-09-09android之計時器(Chronometer)的使用以及常用的方法
在Android的SDK中,為我們提供了一個計時器,這個計時器稱為Chronometer,我們可以成它為Android的一個組件,同時它也具備自己獨有的方法2013-01-01Android RecyclerView的Item自定義動畫及DefaultItemAnimator源碼分析
這篇文章主要介紹了Android RecyclerView的Item自定義動畫及DefaultItemAnimator源碼,感興趣的小伙伴們可以參考一下2016-07-07Android開發(fā)自學筆記(一):Hello,world!
這篇文章主要介紹了Android開發(fā)自學筆記(一):Hello,world!本文講解了創(chuàng)建HelloWorld工程、編寫代碼、啟動模擬器等步驟,需要的朋友可以參考下2015-04-04Android 使用版本控制工具時添加忽略文件的方式(詳解)
下面小編就為大家?guī)硪黄狝ndroid 使用版本控制工具時添加忽略文件的方式(詳解)。小編覺得挺不錯的,現在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-01-01