兩種方式都能實現(xiàn)目標區(qū)別在于場景不同
jitpack 步驟簡單褥琐,適用于開源
nexus 步驟稍微復雜點,適合公司同事間協(xié)作開發(fā)
接下來進入主題...
使用jitpack 制作第三方庫步驟
-
根目錄下的build.gradle
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
} 在需要制作的module的build.gradle文件頭部加入
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.github.<你的github用戶名>'
3.share your pro in github
4.打開鏈接 https://jitpack.io/ 搜索你的項目 用戶名/項目名 然后就能get it
使用nexus搭建本地maven倉庫制作第三方庫(sdk)
1.下載nexus(mac版本)
a. brew install nexus
brew services start nexus
這種方式下載的nexus是2.X版本的我磁,不推薦使用
b. http://www.sonatype.com/download-oss-sonatype 選擇3.x的版本下載(2.x和3.x差異較大,使用新版較舒服)
然后配置環(huán)境變量
打開命令行 open .bash_profile
export NEXUS_HOME=/Users/zhangxindang/software/nexus-3.15.2-01-mac/nexus-3.15.2-01/bin (根據(jù)你的安裝位置)
使用nexus start 開啟nexus
然后訪問:http://127.0.0.1:8081/
-
使用步驟
登錄sign admin admin123
點擊設(shè)置 --> repositories --> createnewrepositories --> maven2(hosted) --> name storage(def) -->hosted(allow)
然后新建的repositories就在browse界面展示出來了 copy地址 -
Androidstudio中的配置
build.gradle (要制作的module)加入如下腳本
apply plugin: 'maven'
uploadArchives {
configuration = configurations.archives
repositories{
mavenDeployer{ // 從步驟2復制的地址
repository(url: 'http://127.0.0.1:8081/repository/common/') {
//你Nexus的賬戶密碼
authentication(userName: 'admin', password: 'admin123')
}
pom.project {
version '1.0.0'
artifactId 'common'
groupId 'com.docker.common'
packaging 'aar'
description '通用工具層拧揽,提供給core以及上層'
}
}
}
}
然后sync 你的項目休里,點擊androidstudio右側(cè)Gradle面板,找到你的module名字---> Tasks --->upload --(雙擊)-> uploadArchives
看到build success 那么你的庫就ok了 引用步驟
根工程目錄下的build.gradle
buildscript-->
maven(){url 'http://192.168.31.138:8081/repository/common/'} (你步驟2復制的地址)
build.gradle(app的) api 'com.docker.common:common:1.0.0' 引用即可
引用規(guī)則: 步驟3中腳本中的值
com.docker.common(groupId) :common(artifactId) (version):1.0.0
- 這時候的庫只是在本地只能自己使用坏逢,想要給別人使用的兩種方式
a. 搭建服務(wù)器在服務(wù)器上下載 JDK nexus maven 然后重復上面的步驟域帐,應該就可以(未實踐)
b. 給同事使用 需要在nexus的安裝目錄下一直點到etc -->打開nexus-default.properties文件 配置如下
Jetty section
application-port=8081
application-host=127.0.0.1
nexus-args={jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/
Nexus section
nexus-edition=nexus-pro-edition
nexus-features=
nexus-pro-feature
c. 然后在同一wifi段下 讓同事操作步驟4赘被,就可以了 that all
good luck
文末給大家推薦一個好文 https://my.oschina.net/jdking/blog/3019829