我们在AndroidStudio中经常使用implementation 的方式来导入第三方代码,比如
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'
}
这些依赖是如何创建的呢?接下来带你们去实现一下~哈嘿
1.准备工具
AndroidStudio客户端;
注册一个GitHub账号;
安装Git客户端(或者有管理远程代码的工具即可)。
1.先创建个项目

2.创建新的 module

这是创建后的目录:

3.在module下,封装你自己代码,我封装了一个权限请求的工具类,如图

4.Gradle添加依赖
在Project的gradle下添加如下信息:
buildscript {
dependencies {
...
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
...
}

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

6.项目上传GitHub
首先上传之前忽略文件,
file => settings => Version Control => Ignored Files

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上你会看到你的所有项目已经有了刚刚上传的项目

8.上传完之后在github创建release - - >Create new Release


9.填写版本号 发布

10.在jitpack官网 搜索你的github仓库
将GitHub上项目的地址放到输入框中后点击LookUp,然后在点击getit然后将生成的依赖添加到你新创建的项目即可引用。这里有个坑,一定要等它编译完,显示版本号才能引用。稍等几秒就好了

到此就可以了,你可以尝试引用一下试试~~
网友评论