安卓Android studio导入Github中的项目
Github中有非常多的优秀开源项目值得我们借鉴和提供给我们使用,那么我们怎么才能把这些项目导入到Android studio中呢,结合各种网站,我归纳了一下两种方法
一、添加github项目作为依赖库——直接clone
1.使用Git或者乌龟Git,其中的Clone命令,将Github上的项目拉到本地仓库中来,这里使用https://github.com/Prokky/ClearRecyclerAdapter 来做例子

2.之后在AS中导入刚才拉到本地仓库的project

3.在导入的project中选择对应的gradle文件

4.打开想要导入该开源库的项目的gradle文件

5.在dependencies中添加编译命令行compile

6.这行编译命令行可以在Github的项目readme.md文件中找到

dependencies { compile'com.prokkypew:clearrecycleradapter:1.1.0'}
关闭Gradle文件,等待AS编译后就可成功使用该项目依赖包
二、添加github项目作为依赖库——使用jitpack导入依赖库
1.登陆JitPack官网
https://jitpack.io/#singwhatiwanna/PinnedHeaderExpandableListView/3dc169178c

2.填入相应的github项目链接,点击lookup,这里以https://github.com/mountainblade/modular 这个例子来举例

3.可以得到相应的项目,并点击get it.

4.点击Get it后可以得到该项目添加的方法

5.按照其中的提示将相关代码填入自己的项目的Gradle文件中
repositories {
maven {url"https://jitpack.io" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.github.mountainblade:modular:4bf87e0a75'
}
关闭Gradle文件,等待AS编译后就可成功使用该项目依赖包