android开发Execution failed for task ':bundleDebugAar'...Direct local .aar file dependencies are not supported when building an AAR...编译错误解决方法

1. 问题描述

  • [ +103 ms] FAILURE: Build failed with an exception.
    [ ] * What went wrong:
    [ ] Execution failed for task ':jpush_flutter:bundleDebugAar'.
    [ ] > Error while evaluating property 'hasLocalAarDeps' of task ':jpush_flutter: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 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 :jpush_flutter project caused this error: D:\work\app\common\plugins\jpush_flutter\android\libs\com.heytap.msp-push-3.1.0.aar

2. 原因分析


implementation files('libs/com.heytap.msp-push-3.1.0.aar') //当前项目子模块这样引入aar包,gradle4.0之后是Android子模块编译是不支持的

  • 出现这个编译报错的原因是,编译Android子项目的时候,引入的libs包下的com.heytap.msp-push-3.1.0.aar文件,Android模块编译在gradle4.0之后是不支持本地直接引入aar包的方式使用aar依赖库了,只能通过maven远程依赖的方式引入aar依赖包。
  • 注意:我这里说的是子模块直接引入本地aar才有这个问题,主模块这样引入本地aar文件是没有问题的

3. 解决方法

  • 解决方法1

  • 1.1. 先修改子模块的implementation files('libs/com.heytap.msp-push-3.1.0.aar') 为compileOnly,让编译通过先,但是注意:这样是可以编译成功了运行是会报错的

  • 1.2. 第一步这样编译通过了,运行报错,因为compileOnly只是编译,没有打包进去apk,下面就再拷贝一份到主模块,使用implementation引用进去,这样就可以解决问题了

  • 解决方法2

  • 2.1. 构建本地仓库maven,这里使用com.heytap.msp-push-3.1.0.aar文件作为例子

  • msp-push-3.1.0.pom文件内容如下,主要是指定groupId、artifactId、version等等信息,项目使用的implementation首先是找到这个pom文件的,然后再自动获取同目录下的同名aar文件

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.heytap</groupId>
  <artifactId>msp-push</artifactId>
  <version>3.1.0</version>
  <packaging>aar</packaging>
</project>
  • 2.2. 和引用远程仓库一样引入本地仓库
posted @ 2024-09-30 18:39  yongfengnice  阅读(2)  评论(0编辑  收藏  举报