Android Studio打包jar及aar包的方法
作者:王永迪 时间:2023-06-18 15:59:53
Android Studio 打包 jar 及 aar 包
创建工程
New -> Module -> Library
在gradle文件头添加 apply plugin: 'com.android.library'
打包模块
在库工程的 build.gradle 中最下方加入如下配置示例:
// 删除已存在的 Jar 包
task deleteOldJar(type: Delete) {
delete 'build/libs/analytics.jar'
}
// 创建 Jar 包
task makeJar(type: org.gradle.api.tasks.bundling.Jar) {
// 指定生成的jar名
baseName 'analytics'
// 指定 cn/soulapp/android/lib 包名目录
from('build/intermediates/classes/debug/cn/soulapp/android/lib/')
// jar包的目录结构(文件处于cn/soulapp/android/lib目录下)
// 生成的jar包没有包名
into('cn/soulapp/android/lib/')
//去掉不需要打包的目录和文件
exclude('BuildConfig.class', 'R.class')
//去掉R$开头的文件
exclude { it.name.startsWith('R$'); }
}
执行命令
./gradlew makeJar
Jar 包输出目录
导入依赖
在 app 宿主工程的 build.gradle dependencies {} 中加入:
implementation fileTree(dir: 'libs', include: ['*.jar'])
导入依赖
结语
导入完成,您可以将自己的公共模块已 jar 报的形势依赖,达成解耦及复用效果。
来源:https://www.jianshu.com/p/81f00136fcae
标签:Android,Studio,jar,aar
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java 8 开发的 Mybatis 注解代码生成工具
2023-01-02 19:53:44
![](https://img.aspxhome.com/file/2023/1/66211_0s.png)
手把手教你SpringBoot快速集成Swagger的配置过程
2023-10-30 01:16:22
![](https://img.aspxhome.com/file/2023/5/58705_0s.png)
浅谈Java锁机制
2022-01-09 00:58:56
关于Java中Json的各种处理
2022-06-12 02:37:48
Java 深入浅出分析Synchronized原理与Callable接口
2021-11-26 10:27:17
![](https://img.aspxhome.com/file/2023/8/64898_0s.png)
C语言在输入输出时遇到的常见问题总结
2021-11-08 15:22:37
spring boot+vue实现JSAPI微信支付的完整步骤
2023-07-31 13:39:26
![](https://img.aspxhome.com/file/2023/5/110635_0s.png)
在mybatis中使用mapper进行if条件判断
2023-08-01 08:09:34
SpringBoot读写操作yml配置文件方法
2023-10-11 00:13:03
![](https://img.aspxhome.com/file/2023/8/99918_0s.png)
Guava中这些Map技巧可以让代码量减少了50%
2023-03-16 02:35:42
![](https://img.aspxhome.com/file/2023/6/103816_0s.jpg)
Java中LinkedList和ArrayList的效率分析
2023-02-12 06:21:55
![](https://img.aspxhome.com/file/2023/9/61809_0s.png)
Kotlin实现在类里面创建main函数
2022-08-26 20:11:13
![](https://img.aspxhome.com/file/2023/7/94997_0s.jpg)
Android点击WebView实现图片缩放及滑动浏览效果
2021-12-12 19:32:48
![](https://img.aspxhome.com/file/2023/7/138197_0s.jpg)
java中重写equals()方法的同时要重写hashcode()方法(详解)
2022-03-07 22:29:20
![](https://img.aspxhome.com/file/2023/4/71664_0s.jpg)
Log4j新手快速入门教程
2023-06-01 11:59:44
![](https://img.aspxhome.com/file/2023/0/91740_0s.png)
Java锁之可重入锁介绍
2021-06-01 03:05:19
springcloud引入spring-cloud-starter-openfeign失败的解决
2022-10-30 19:15:09
![](https://img.aspxhome.com/file/2023/7/110827_0s.png)
Java数据结构中堆的向下和向上调整解析
2022-01-02 07:34:58
![](https://img.aspxhome.com/file/2023/2/81982_0s.png)
使用java打印心型、圆形图案的实现代码
2021-08-30 19:50:45
![](https://img.aspxhome.com/file/2023/9/66649_0s.jpg)
详解如何将Spring Boot应用跑在Docker容器中
2023-04-25 08:08:58
![](https://img.aspxhome.com/file/2023/8/77158_0s.jpg)