androidandroid-gradle-pluginaar

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


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?

Solution

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