how to add .aar file to gradle.kts in android studio?

12.9k views Asked by At

implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))

implementation(files("BudgetLibraryNBB.aar"))

2

There are 2 answers

1
Krystian Kaniowski On

This is really simple, just include *.aar in fileTree

implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))

PS. of course if you still keep your library in libs dir

0
Victor On

The recommond method is import it using File -> New -> New Module -> Import .JAR/.AAR Package, then referencing it in the library module build.gradle.kts file:

implementation(project(":BudgetLibraryNBB"))

If you put it into libs dir:

implementation(files("./libs/BudgetLibraryNBB.aar"))

or

implementation(files("$projectDir/libs/BudgetLibraryNBB.aar"))

when you are executing bundleAar task, you will meet error below:

Execution failed for task ':common: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 :common project caused this error: