Android studio下,有几种包可以放出去给别的项目调用,这里介绍jar和aar如何用as创建,可能有些简单,但确实有不会的,如有错误,请大牛指正。
一 jar包的创建
1.新建一个空白工程。

新建一个module文件


2.新建一个jar可使用的方法



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| //task to delete the old jar
task deleteOldJar(type: Delete) {
delete 'release/AndroidPlugin.jar'
}
//task to export contents as jar
task exportJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('release/')
include('classes.jar')
///Rename the jar
rename('classes.jar', 'WX.jar')
}
exportJar.dependsOn(deleteOldJar, build)
|
3.运行



双击运行

运行完毕后,这个jar包就是咱们要的了。
二 aar包
首先aar包和jar包区别在哪呢,区别在于jar包中只含有class源码文件,而aar包则可以含有资源文件,调用起来更加方便
1.仍然是新建一个项目和一个library文件,同上,就不截图了
2.仍然是写一个方法,等会用于验证,同上,不截图了
3.方法写完了,进行Rebulid操作

rebuild完成后

这个aar包就是我们需要的了。