构建 Android 库时出错:不支持直接本地 .aar 文件依

时间:2023-02-13
本文介绍了构建 Android 库时出错:不支持直接本地 .aar 文件依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近升级到了 Android Gradle 插件 4.0.0-beta03.我们现在在构建我们的库模块之一时看到此错误

<上一页>$ ./gradlew library_module: 组装任务 ':library_module:bundleDebugAar' 执行失败.> 构建 AAR 时不支持直接本地 .aar 文件依赖项.生成的 AAR 将被破坏,因为来自任何本地 .aar 的类和 Android 资源文件依赖项不会打包在生成的 AAR 中.以前版本的 Android在这种情况下,Gradle 插件也会产生损坏的 AAR(尽管没有抛出此错误).这以下 :library_module 项目的直接本地 .aar 文件依赖项导致此错误:______.aar

我可以看到这是几个月前添加到 AGP.但他们没有提供有关原因的更多信息.

所以.

  1. 出了什么问题?还有更多信息吗?我在任何地方都找不到一个错误报告.
  2. 我该如何解决这个问题?这是否是说我不能建立一个依赖于其他本地 .aar 的 .aar?如果这个本地 aar 托管在 Maven Central 或其他远程仓库上会怎样?为什么会有不同?

解决方案

我最近遇到了同样的问题,解决方法是从 libs/ 中删除库并使用 File 导入它 ->新 ->新模块 ->导入.JAR/.AAR Package,然后在库模块build.gradle文件中引用:

依赖项{实施项目(:imported_aar_module")}

如果您使用的是较新的 Android Studio 版本 (4.0.0+),则此选项不可用.相反,您必须手动完成.

  1. 新建一个目录,将以下内容放入新目录下的build.gradle文件中:

configurations.maybeCreate("default")artifacts.add("default", file('[nameOfTheAar].aar'))

  1. aar 放入这个新目录中.build.gradle 文件旁边.
  2. 将新建的 Gradle 项目添加到 settings.gradle 文件中:

include(":pathToTheCreatedDirectory")

  1. 将项目包含在您要使用 aar 的库中:

实施项目(":pathToTheCreatedDirectory", configuration = "default")

We recently upgraded to Android Gradle Plugin 4.0.0-beta03. We are now seeing this error when building one of our library modules

$ ./gradlew library_module:assemble

Execution failed for task ':library_module: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 :library_module project caused this error: 
______.aar

I can see this was added to AGP a few months ago. But they provide no further info on why.

So.

  1. What was the problem? Any more info? I can't find a single bug report anywhere.
  2. How exactly can I fix this? Is this saying that I can't build one .aar that depends on other local .aars? What if this local aar was instead hosted on Maven Central or another remote repo? Why would that make a difference?

解决方案

I recently encountered the same issue, the fix was to remove the library from libs/ and import it using File -> New -> New Module -> Import .JAR/.AAR Package, then referencing it in the library module build.gradle file:

dependencies {
  implementation project(":imported_aar_module")
}

If you are on a newer Android Studio version (4.0.0+), this option is not available. Instead you have to do it manually.

  1. Create a new directory and put the following content into the build.gradle file withing the new directory:

configurations.maybeCreate("default")
artifacts.add("default", file('[nameOfTheAar].aar'))

  1. Place the aar into this new directoy. Next to the build.gradle file.
  2. Add the new created Gradle project to the settings.gradle file:

include(":pathToTheCreatedDirectory")

  1. Include the project in your library where you want to use the aar:

implementation project(":pathToTheCreatedDirectory", configuration = "default")

这篇关于构建 Android 库时出错:不支持直接本地 .aar 文件依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:Android Studio Gradle:错误:任务':app:processDebugGoog 下一篇:“minifyEnabled"和“minifyEnabled"有什么区别

相关文章

最新文章