赞
踩
Android 打包aar包含第三方aar
因项目需要,打包aar包含第三方aar,如果直接对module进行打包会产生一些问题。
* What went wrong:
Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error). The following direct local .aar file dependencies of the :httpLibrary project caused this error: D:\AndroidWorkSpace\mackSdk\mackSDK\httpLibrary\libs\xxxxx.aar
错误信息说的很清楚构建aar不支持本地aar文件依赖
解决方案:
fat-aar 能将依赖项合并并嵌入到生成的aar文件中。
fat-aar项目地址:https://github.com/adwiv/android-fat-aar
由于fat-aar不再维护,使用起来有诸多需要修改的地方,而不支持高版本的gradle,极其坑爹,踩坑后找到替代方案,支持高版本的gradle无需修改脚本文件
fat-aar-android:https://github.com/kezong/fat-aar-android
在dependencies中以如下方式依赖第三方aar
apply plugin: 'com.kezong.fat-aar'
在dependencies中以如下方式依赖第三方aar
classpath 'com.github.kezong:fat-aar:1.3.8'
- implementation('com.squareup.okhttp3:okhttp:4.11.0')
- 改为:
- embed('com.squareup.okhttp3:okhttp:4.11.0')
- implementation files("libs/xxx.aar")
- 改为:
- embed(name: 'animplayer', ext: 'aar')
- //需要加上这个
- compileOnly fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
我们不需要这些so库的话可以过滤掉
在需要打包的模块build中加入要过滤的so
- android{
- //不需要把这些架构打进去
- packagingOptions {
- exclude 'lib/x86/*.so'
- exclude 'lib/x86_64/*.so'
- }
- }
最终生成的aar在module下的build中
参考:https://blog.csdn.net/Mr_ziheng/article/details/131010454
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。