本文僅供自己參考,所以不詳細(xì)寫,只追求自己看的懂
一、生成aar并上傳到github
1、把項(xiàng)目改為library或者在項(xiàng)目下新建一個(gè)File--new module--android library,如果是項(xiàng)目改的注意刪除啟動(dòng)標(biāo)簽,
沒有activity的把manifest中的application也刪了,用不到的第三方庫全刪了,測試模塊也可以刪了。
點(diǎn)擊studio右側(cè)gradle 插件,點(diǎn)擊library模塊 build下的 assemble 可以生成aar(因?yàn)槭琼?xiàng)目改的所以library模塊名就叫app沒有重新再改),在library的build--outputs下,這個(gè)就可以直接用添加用了

2、如果是要生成上傳到GitHub的,在library 的gradle 末尾 添加
applyplugin:'maven'
uploadArchives {
repositories.mavenDeployer {
// 本地存放目錄(自行選擇),可放在gradle.properties文件中引用
def mavenDirPath = file('F:\\mavendir')
// 必須雙引號(hào),單引號(hào)不會(huì)轉(zhuǎn)義$
repository(url:"file://${mavenDirPath.absolutePath}")
pom.project {
// 可以隨意取,一般取包名
groupId"com.example.testcreatearr"
// 可以隨意取,一般取庫的名字
artifactId"app"
// 版本號(hào)
version"1.0.0"
}
}
}
然后在gradle插架,library下點(diǎn)擊uploadArchives

文件就保存在,設(shè)置的本地目錄下
def mavenDirPath = file('F:\mavendir')
為這個(gè)文件夾添加git控制,在GitHub中創(chuàng)建一個(gè)倉庫,把文件傳上去,如果要在項(xiàng)目中引用則在package的gradle中添加
maven { url "https://raw.githubusercontent.com/wozaihu/testmaven/master" }
不同倉庫鏈接當(dāng)然不同,用戶名是這個(gè)倉庫所有者的github用戶名,
maven { url "https://raw.githubusercontent.com/用戶名/倉庫名/master" }

在app的gradle下引用
implementation 'com.example.testcreatearr:app:1.0.0'
這里就是上面寫的
implementation 'groupId:artifactId:version'
如果出現(xiàn) unable to resolve dependency for app@......
看能不能訪問https://raw.githubusercontent.com
不能就在C:\Windows\System32\drivers\etc路徑下找到hosts文件
添加 以下內(nèi)容并保存即可訪問(如果這個(gè)地址也用不了了,就在找其他的)
199.232.68.133 raw.githubusercontent.com