android studio 导入第三方库的记录
最后更新于:2022-04-01 19:52:31
android studio 导入第三方库的记录。jar包 和 库
一、jar包
1.jar包的话很简单,首先换成project模式,将你要用的jar包复制到lib下面。如图
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-02-23_56cbd2dd2bf0a.jpg)
2.然后右键选择Add as libary(多个jar也只要随便选一个就这样添加就好了).
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-02-23_56cbd2dd41832.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-02-23_56cbd2dd606a5.jpg)
3.或者按住 shirt + ctrl + alt + s,然后按图所示选择文件添加。
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-02-23_56cbd2dd754d9.jpg)
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-02-23_56cbd2dd8fc86.jpg)
二、库
1.首先下载好你需要的库,然后复制到你的工程目录下。
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-02-23_56cbd2dda199a.jpg)
2.然后在上图新加的库文件夹下新建一个build.gradle文件,代码如下
~~~
buildscript {
repositories {
mavenCentral()
}
dependencies {
//这里要和你项目下面的build.gradle里面的classpath一样
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'com.android.library'
dependencies {
//这里是添加你要依赖的包
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
android {
//编译版本选择你自己的最高版本
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
//这里按自己需要自己修改
minSdkVersion 15
targetSdkVersion 23
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
~~~
3.在1中图片你面的settings.gradle里面添加 **':依赖库的名字' **
例如 include**':app'**,**':library'**
4.然后在app目录下的build.gradle 的dependencies下面添加compile project(**':**依赖库的名字**'**)
例如:
![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-02-23_56cbd2deb5825.jpg)
';