問題描述
我們最近升級到了 Android Gradle 插件 4.0.0-beta03.我們現(xiàn)在在構(gòu)建我們的庫模塊之一時(shí)看到此錯(cuò)誤
<上一頁>$ ./gradlew library_module: 組裝任務(wù) ':library_module:bundleDebugAar' 執(zhí)行失敗.> 構(gòu)建 AAR 時(shí)不支持直接本地 .aar 文件依賴項(xiàng).生成的 AAR 將被破壞,因?yàn)閬碜匀魏伪镜?.aar 的類和 Android 資源文件依賴項(xiàng)不會(huì)打包在生成的 AAR 中.以前版本的 Android在這種情況下,Gradle 插件也會(huì)產(chǎn)生損壞的 AAR(盡管沒有拋出此錯(cuò)誤).這以下 :library_module 項(xiàng)目的直接本地 .aar 文件依賴項(xiàng)導(dǎo)致此錯(cuò)誤:______.aar我可以看到這是幾個(gè)月前添加到 AGP.但他們沒有提供有關(guān)原因的更多信息.
所以.
- 出了什么問題?還有更多信息嗎?我在任何地方都找不到一個(gè)錯(cuò)誤報(bào)告.
- 我該如何解決這個(gè)問題?這是否是說我不能建立一個(gè)依賴于其他本地 .aar 的 .aar?如果這個(gè)本地 aar 托管在 Maven Central 或其他遠(yuǎn)程倉庫上會(huì)怎樣?為什么會(huì)有不同?
我最近遇到了同樣的問題,解決方法是從 libs/
中刪除庫并使用 File 導(dǎo)入它 ->新 ->新模塊 ->導(dǎo)入.JAR/.AAR Package
,然后在庫模塊build.gradle
文件中引用:
依賴項(xiàng){實(shí)施項(xiàng)目(:imported_aar_module")}
如果您使用的是較新的 Android Studio 版本 (4.0.0+),則此選項(xiàng)不可用.相反,您必須手動(dòng)完成.
- 新建一個(gè)目錄,將以下內(nèi)容放入新目錄下的
build.gradle
文件中:
configurations.maybeCreate("default")artifacts.add("default", file('[nameOfTheAar].aar'))
- 將
aar
放入這個(gè)新目錄中.build.gradle
文件旁邊. - 將新建的 Gradle 項(xiàng)目添加到
settings.gradle
文件中:
include(":pathToTheCreatedDirectory")
- 將項(xiàng)目包含在您要使用
aar
的庫中:
實(shí)施項(xiàng)目(":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")
這篇關(guān)于構(gòu)建 Android 庫時(shí)出錯(cuò):不支持直接本地 .aar 文件依賴項(xiàng)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!