*本篇文章已授權(quán)微信公眾號(hào) guolin_blog (郭霖)獨(dú)家發(fā)布
*本篇文章視頻 慕課網(wǎng)之Android依賴管理與私服搭建
1.Android引入依賴的多種方式
2.多平臺(tái)私服搭建
3.創(chuàng)建和依賴自己的代碼倉庫
1践盼、Android引入依賴的多種方式
引入方式一
AS切換project視圖>新建libs目錄(高版本AS默認(rèn)存在libs目錄)>copy jar 包>add as library
下面以我開源的支付寶以及微信app支付項(xiàng)目為例引入相關(guān)的jar
引入方式二(module>aar)
import module>Project Structure>選擇對(duì)應(yīng)的Module>module dependent
我們知道jar包是不能引入資源文件的躏率,如果已module模式引入資源文件同樣可以使用。
Lib Module 生成aar
New Module >Android Library>實(shí)現(xiàn)包功能并生成aar文件
項(xiàng)目中引用aar文件
以上兩種引入jar依賴弊端就是jar包升級(jí)之后需要Copy替換換新的jar并修改對(duì)應(yīng)的配置文件厌杜。
引入方式三(推薦)
從倉庫中下載引用
找到jar對(duì)應(yīng)的build.gradle>compile(jcenter炫隶、mavencenter咳燕、mavenlocal)>通過Nexue搭建私服
https://bintray.com/bintray/jcenter
http://search.maven.org
http://www.sonatype.org
部分網(wǎng)站訪問需要科學(xué)上網(wǎng)撼泛,你懂的哈
Android Studio最新版默認(rèn)使用的是jcenter麦撵,好處就是jar包升級(jí)自需要修改版本號(hào)上遥,構(gòu)建項(xiàng)目會(huì)自動(dòng)從倉庫中下載(只會(huì)下載一次搏屑,下載以后會(huì)從本地引入)。
如何引入倉庫中的jar
下面以引入retrofit為例
或者直接在對(duì)應(yīng)項(xiàng)目Module的build.gradle中dependencies節(jié)點(diǎn)添加
compile 'com.squareup.retrofit2:retrofit:2.1.0'
相互依賴的包也會(huì)下載下來粉楚,retrofit依賴okhttp依賴ikoi
2辣恋、多平臺(tái)Nexus私服搭建
http://books.sonatype.com/nexus-book/3.0/reference/index.html
Note: The GUI installer distribution development is suspended and is no longer an install option until further notice.
Nexus Repository Manager 3.1.0-04 開始并沒有提供GUI的安裝程序。建議JDK使用1.8版本模软。
安裝介紹資料
http://books.sonatype.com/nexus-book/3.0/reference/install.html#installation-archive
解壓下載的nexus
$ tar xvzf nexus-3.0.2-02-mac.tgz
$ tar xvzf nexus-3.0.2-02-unix.tar.gz
The bin folder contains the generic startup scripts for Unix-like platforms called nexus. The Windows platform equivalent is called nexus.exe. To start the repository manager from the bin folder on a Unix-like platform like Linux use
./nexus run
The equivalent invocation on Windows requires a / in front of the run and any other commands.
nexus.exe /run
簡(jiǎn)單解釋就是Mac伟骨、Linux平臺(tái)使用./nexus run
Window平臺(tái)使用 nexus.exe /run
運(yùn)行Nexus Repository Manager
Mac
Linux
進(jìn)
bin
目錄,執(zhí)行./nexus run
Nexus Repository Manager依賴的是Java開發(fā)環(huán)境,最新版JDK得1.8或者以上
在nexus的bin目錄修改nexus燃异,設(shè)置
INSTALL4J_JAVA_HOME_OVERRIDE
關(guān)閉防火墻 默認(rèn)端口8081
systemctl stop firewalld
參考質(zhì)料:
http://books.sonatype.com/nexus-book/3.0/reference/install.html#installation-java
2.1携狭、創(chuàng)建自己的倉庫
1、創(chuàng)建用戶
首先使用管理員密碼登陸到Nexus私服并添加用戶
使用新創(chuàng)建的用戶登錄Nexus并創(chuàng)建倉庫
2.2回俐、上傳自己的Module到倉庫
第一 在項(xiàng)目級(jí)別的build.gradle中的allprojects下repositories節(jié)點(diǎn)添加
mavenLocal()
第二 在Lib Module級(jí)別的build.gradle中添加maven插件
apply plugin: 'maven'
第三 在Lib Module級(jí)別的build.gradle中android節(jié)點(diǎn)添加上傳行為
解析:
compile 'com.android.support:appcompat-v7:24.2.1'
pom.version = "24.2.1"
pom.artifactId = "appcompat-v7"
pom.groupId ="com.android.support"
//定義上傳行為
uploadArchives {
//倉庫基于maven
repositories.mavenDeployer {
//配置上傳的url
repository(url: "http://192.168.1.100:8081/repository/com.javen205/") {
authentication(userName: "javen", password: "javen205")
}
pom.version = "0.0.1"
pom.artifactId = "JPay"
pom.groupId = "com.javen205"
}
}
第四 使用Gradle插件上傳aar到Maven私服
點(diǎn)擊uploadArchives自動(dòng)上傳
2.2逛腿、引用私服中的Module
在需要依賴Module的build.gradle中添加如下節(jié)點(diǎn),其中URL就是上文中創(chuàng)建倉庫的url
allprojects {
repositories {
maven {
url "http://192.168.1.100:8081/repository/com.javen205/"
}
}
}
compile 'com.javen205:JPay:0.0.1'
查看 ** External Libraries**
推薦閱讀
Android Studio 上傳aar(Library)到JCenter
Android版-支付寶APP支付
Android版-微信APP支付
支付寶Wap支付你了解多少稀并?
一張二維碼集成微信、支付寶支付
安利時(shí)間:
JPay是對(duì)微信App支付单默、支付寶App支付的二次封裝,對(duì)外提供一個(gè)相對(duì)簡(jiǎn)單的接口以及支付結(jié)果的回調(diào)
極速開發(fā)微信公眾號(hào)是對(duì)微信公眾平臺(tái)接口的二次封裝碘举。包括開發(fā)者模式、事件回調(diào)監(jiān)聽搁廓、微信模板消息引颈、微信客服消息、自定義菜單境蜕、微信支付蝙场、素材管理等
如遇到問題歡迎留言交流
記錄學(xué)習(xí)的點(diǎn)滴,以此勉勵(lì)不斷奮斗的自己?????? 如果對(duì)你有幫助記得點(diǎn)喜歡告訴我