問題描述
我們最近升級到了 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 文件依賴項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!