Error building Android library: Direct local .aar file dependencies are not supported

tir38 picture tir38 · Mar 27, 2020 · Viewed 15.7k times · Source

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?

Answer

Sandi picture Sandi · Mar 27, 2020

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")
}