Android Studio 关于AAR 的打包引用

本文介绍了Android Studio中AAR文件的组成结构及其用途。详细讲述了如何将一个Library Module打包成AAR,并提供了正确的AAR引入方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在使用Android Studio 进行编译时,发现了AAR 的压缩包,里面包含了资源文件及class文件等!之后查询了有关AAR 的说明:

1.AAR说明

文档地址;http://tools.android.com/tech-docs/new-build-system/aar-format

AAR Format
The 'aar' bundle is the binary distribution of an Android Library Project.

The file extension is .aar, and the maven artifact type should be aar as well, but the file itself a simple zip file with the following entries:
/AndroidManifest.xml (mandatory)
/classes.jar (mandatory)
/res/ (mandatory)
/R.txt (mandatory)
/assets/ (optional)
/libs/*.jar (optional)
/jni/<abi>/*.so (optional)
/proguard.txt (optional)
/lint.jar (optional)
These entries are directly at the root of the zip file.

The R.txt file is the output of aapt with --output-text-symbols.```

看到这个目录,不就是梦寐以求的资源文件打包嘛!很兴奋的,有没有?哈哈……
通过这次查询关于AAR的说明,发现这个网址还是不错的,有许多关于Android Studio的使用说明,
http://tools.android.com/tech-docs/new-build-system/

2,AAR 打包

1>对一个Module进行打包成AAR,首先这个Module应该是一个Library,如果是一个Applicateion,就没必要打包成AAR而直接生成apk了,所以首先要确保这个Module是个Library!
2>在命令行进入到该Module的文件夹下(下面的是我的Library Module的文件夹下的文件):
/WyfCode/data$ ls
build.gradle data.iml libs proguard-rules.pro src

3> 直接执行命令:
gradle build
4.成功执行上述命令后,该Module文件夹下会多出一个文件夹:build, 如下所示:

/WyfCode/data$ ls
build  build.gradle    data.iml  libs  proguard-rules.pro  src

打包好的aar在目录/build/outputs/aar/ 下面

3.引用AAR

更正一下:下面的引用方式引用不了
转自:http://stackoverflow.com/questions/16682847/how-to-manually-include-external-aar-package-using-new-gradle-android-build-syst

``
Lets say you have kept aar file in libs folder. ( assume file name is cards.aar )

then in app build.gradle specify following and click sync project with Gradle files.

repositories {
flatDir {
dirs ‘libs’
}
}

dependencies {
compile(name:’cards’, ext:’aar’)
}
If everything goes well you will see library entry is made in build -> exploded-aar

正确是引用方式:
1,使用Ctrl+Alt+shift+S 组合键,打开Project structure
2。点击+ 按钮,选择导入
Import .JAR or .AAR Package
3。选择aar包即可 ,然后添加Module library

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值