7

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

implementation(files("BudgetLibraryNBB.aar"))

Syed Danish Haider
  • 1,334
  • 11
  • 15
  • i have .aar file in libs folder and i want to import the .aar currently in libs folder to include in the main project..please note that i am using Gradle.kts file system. i just tried to use many online solution but so far it seems not wokring.if anybod can be check this.Below is the given question – Syed Danish Haider May 12 '20 at 10:49

2 Answers2

9

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: 

Victor
  • 482
  • 6
  • 13
6

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

Krystian Kaniowski
  • 1,959
  • 17
  • 33