问题描述
我们最近升级到了 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.但他们没有提供有关原因的更多信息.
所以.
- 出了什么问题?还有更多信息吗?我在任何地方都找不到一个错误报告.
- 我该如何解决这个问题?这是否是说我不能建立一个依赖于其他本地 .aar 的 .aar?如果这个本地 aar 托管在 Maven Central 或其他远程仓库上会怎样?为什么会有不同?
我最近遇到了同样的问题,解决方法是从 libs/
中删除库并使用 File 导入它 ->新 ->新模块 ->导入.JAR/.AAR Package
,然后在库模块build.gradle
文件中引用:
依赖项{实施项目(:imported_aar_module")}
如果您使用的是较新的 Android Studio 版本 (4.0.0+),则此选项不可用.相反,您必须手动完成.
- 新建一个目录,将以下内容放入新目录下的
build.gradle
文件中:
configurations.maybeCreate("default")artifacts.add("default", file('[nameOfTheAar].aar'))
- 将
aar
放入这个新目录中.build.gradle
文件旁边. - 将新建的 Gradle 项目添加到
settings.gradle
文件中:
include(":pathToTheCreatedDirectory")
- 将项目包含在您要使用
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.
- What was the problem? Any more info? I can't find a single bug report anywhere.
- 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.
- 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'))
- Place the
aar
into this new directoy. Next to thebuild.gradle
file. - Add the new created Gradle project to the
settings.gradle
file:
include(":pathToTheCreatedDirectory")
- Include the project in your library where you want to use the
aar
:
implementation project(":pathToTheCreatedDirectory", configuration = "default")
这篇关于构建 Android 库时出错:不支持直接本地 .aar 文件依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!