Android Studio导入aar文件并配置使用

来源:互联网 发布:费根鲍姆常数 知乎 编辑:程序博客网 时间:2024/05/17 01:47

如何在Android studio中,给android 项目添加外部lib引用,以前使用Ec时,大多是直接导入jar文件,而在使用Android Studio 后,发现更多的是aar文件,因此正确导入aar文件并配置好尤为重要了,下面就我自己操作的记录如下:

在android studio中,有两种方式:

一种是jar包,一种是带资源文件的aar包,

jar: 只包含了class文件与清单文件 ,不包含资源文件,如图片等所有res中的文件。

aar: 包含jar包和资源文件,如图片等所有res中的文件

这里将着重介绍如何使用本地的aar包

一:复制外部aar包到libs目录下。

二:修改build.gradle 配置文件:

1:添加

repositories{    flatDir{        dirs 'libs'    }}

这个是添加一个本地仓库,并把libs目录作为仓库的地址。


2:修改dependencies:

添加一行:

dependencies {    compile fileTree(include: ['*.jar'], dir: 'libs')    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {        exclude group: 'com.android.support', module: 'support-annotations'    })    compile 'com.android.support:appcompat-v7:25.2.0'    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'    testCompile 'junit:junit:4.12'    compile files('libs/xUtils.jar')    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'    //引入aar文件    compile(name:'xxx-1.1.0-20170527.103123-13',ext:'aar')}

其中name就是libs目录下

xxx-1.1.0-20170527.103123-13 s
.aar文件名称,

ext,就是

xxx-1.1.0-20170527.103123-13.aar
的扩展名


3.重新编译项目:

从工具栏依次选择:"Build"-->"rebuild project"

这个时候我们就可以在项目中使用第三包的类了。

原创粉丝点击