一,build报错信息:
Execution failed for task ':cmm_xxx:bundleDebugAar'.
> 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 packa
ged 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 :cmm_ab
project caused this error: D:\work\xxxx\xxxsdk\cmm_xxxx\libs_ab\play-services-ads-20.1.0.aar, D:\work\xxxx\xxxsdk\cmm_xxxx\libs_ab\play-services-ads-base-20.1.0.aar, D:\work\xxxx\xxxsdk\cmm_xxxx\libs_ab\play
-services-ads-identifier-17.0.0.aar .......
二,分析原因&解决方案:
构建过程无法读取并使用依赖包的aar文件,然后回去查看build.gradle文件是设置了
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs_ab')
明明设置了依赖,为什么读取不到呢,然后去检查 repositories
repositories {
flatDir {
dirs 'libs'
dirs 'libs_ab' // 把这个加上也是不行
}
}
然后搜索引擎查找原因和解决办法,都无法解决问题,但是对比了一下其他能够build成功的项目的差异性,将
implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs_ab')
改成
implementation(name: 'xxx.xxx.xxx', ext: 'aar')
然后重新build,就构建成功的了.
即:
implementation(name: 'play-services-ads-20.1.0', ext: 'aar')
implementation(name: 'play-services-ads-base-20.1.0', ext: 'aar')
implementation(name: 'play-services-ads-identifier-17.0.0', ext: 'aar')
implementation(name: 'play-services-ads-lite-20.1.0', ext: 'aar')
......
必须要使用gradle对应的依赖引入方法格式,才能保证build成功。