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

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


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


When building an Android library that depends on other Android libraries (i.e., aar files), you will get the following error message if you include the aar files as dependencies in the project:

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).

As the above message states, when you build an Android library project, any aar it depends on is not packaged. If you built this way prior to AGP (Android Gradle Plugin) 4, you probably noticed that you had to include the aar dependencies on the project consuming your library.

You can compile your Android library project by specifying that the aar dependencies are compileOnly. See this for more info on when to use compileOnly.

So just add the following to your app build.gradle file:

compileOnly files('libs/some-library.aar')

Note that if you do this you will have to include the aar dependencies on the application project that consumes your library.

Alternatively, you can create a module that imports your aar dependency as @Sandi mentioned in the answer above.

Another way is to publish your aar dependencies to a maven repository and then add them to your library project like this:

implementation 'mylibrarygroup:mylibraryartifact:version-x.y.z@aar'


In my experience, when Gradle Plugin version is 4.2.2+ and Gradle version is 7.1+, as in @Luis's answer 'compileOnly' works.

compileOnly files('libs/your_library_name.aar')

It didn't work when the Gradle versions were lower.