Android Studio 关于AAR 的打包引用

今天在使用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`

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。