Derect local .aar file dependencies are not supported when building an AAR

背景

项目中需要将部分功能业务打包成aar包供其它项目调用,我引入了fataar(具体使用方式见github)。实际打包过程中抛出错误Derect local .aar file dependencies are not supported when building an AAR

原因分析

我们项目中lib文件夹下导入了很多jar包、aar包,在之前没有引入aar包时,打包是正常的。所以问题就出在使用aar包二次编译成aar,就会抛出该错误

解决

  1. 在工程下新建文件夹 aarLib(这个文件夹可自定义名称) 并在里新建build.gradle文件,文件内容如下:
    configurations.maybeCreate("default")
    artifacts.add("default", file('aar名称.aar'))
  2. 将本地 aar 放入这个新建的文件夹目录中
  3. 将新创建文件夹项目添加到settings.gradle文件中:
    include ':aarLib'
  4. 将新建项目包含导入到Lib库中
    implementation project(path: ':aarLib')
    PS:使用fataar如果需要将aarLib中的aar包打包进最终aar,应该使用替代写法
    embed project(path: ':aarLib')
    aarLib文件夹位置目录结构参考
    image
posted @ 2024-07-03 17:50  瓜的呱  阅读(1085)  评论(0)    收藏  举报