Android Studio 关于AAR 的打包引用

来源:互联网 发布:sql语句与语法 编辑:程序博客网 时间:2024/05/01 00:56

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

1.AAR说明

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

AAR FormatThe '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$ lsbuild  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

1 0