Android studio 怎么打包成aar包和引用aar包

目录

1.首先什么是aar格式

2. 怎么把一个模块编译成一个aar

首先把鼠标放到要编译的模块上

然后再点击:Build ->Build  Module 'xxx' 刚刚鼠标选的模块

最后生成的aar包在这里

3. 怎么引用aar包

例如我把我刚刚编译的aar包放到 我要引用的app/build/libs/xx.aar

修改这个APP 的build.grade


 

1.首先什么是aar格式

看看官网的说明:

http://tools.android.com/tech-docs/new-build-system/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.
 
也就是说是相当于Android工程里的一个module 打包成一个aar的压缩包模式
 

2. 怎么把一个模块编译成一个aar

首先把鼠标放到要编译的模块上

然后再点击:Build ->Build  Module 'xxx' 刚刚鼠标选的模块

最后生成的aar包在这里

3. 怎么引用aar包

例如我把我刚刚编译的aar包放到 我要引用的app/build/libs/xx.aar

修改这个APP 的build.grade

新加如下:

然后再Mainactivity.java 里面引用aar中的class啦

import com.xx.TAInterface;

发布了47 篇原创文章 · 获赞 44 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/yang_quan_yang/article/details/105764133
今日推荐