我們在AndroidStudio中經(jīng)常使用implementation 的方式來導(dǎo)入第三方代碼,比如
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
}
這些依賴是如何創(chuàng)建的呢?接下來帶你們?nèi)?shí)現(xiàn)一下~哈嘿
1.準(zhǔn)備工具
? AndroidStudio客戶端;
? 注冊一個GitHub賬號;
? 安裝Git客戶端(或者有管理遠(yuǎn)程代碼的工具即可)。
1.先創(chuàng)建個項目

創(chuàng)建項目.png
2.創(chuàng)建新的 module

創(chuàng)建module.png
這是創(chuàng)建后的目錄:

工程目錄.png
3.在module下,封裝你自己代碼,我封裝了一個權(quán)限請求的工具類,如圖

權(quán)限工具類.png
4.Gradle添加依賴
在Project的gradle下添加如下信息:
buildscript {
dependencies {
...
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
...
}

項目gradle.png
5.在Moudle的library 的gradle 添加如下信息:
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.YourUsername'

modulegradle.png
6.項目上傳GitHub
首先上傳之前忽略文件,
file => settings => Version Control => Ignored Files

忽略文件.png
Directory: .gradle/ 表示忽略.gradle文件夾下所有文件
Directory: .idea/ 表示忽略.idea文件夾下所有文件
Directory: build/ 表示忽略build文件夾下所有文件
Directory: app/build/ 表示忽略app/build文件夾下所有文件
File: local.properties 表示忽略local.properties文件
Mask: *.iml 表示忽略所有iml格式的文件。
7.上傳github

上傳github.png

上傳文件.png
在github上你會看到你的所有項目已經(jīng)有了剛剛上傳的項目

github.png
8.上傳完之后在github創(chuàng)建release - - >Create new Release

添加releases.png

添加release2.png
9.填寫版本號 發(fā)布

發(fā)布release.png
10.在jitpack官網(wǎng) 搜索你的github倉庫
將GitHub上項目的地址放到輸入框中后點(diǎn)擊LookUp,然后在點(diǎn)擊getit然后將生成的依賴添加到你新創(chuàng)建的項目即可引用。這里有個坑,一定要等它編譯完,顯示版本號才能引用。稍等幾秒就好了

完成.png
到此就可以了,你可以嘗試引用一下試試~~