Mirian Okradze
Mirian Okradze

Reputation: 355

Create Android library that uses AAR file as dependency

I want to build android library as AAR file that includes dependencies in output AAR file. It uses another AAR file as dependency from libs folder.

enter image description here

Building library shows this error:

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.

I tried extracting AAR file as module enter image description here

And then imported it as a project enter image description here

Build command worked, but it does not include external library in classes.jar enter image description here

My proguard-rules.pro file is

-dontwarn javax.annotation.Nullable
-dontwarn com.facetec.sdk.**
-keep class com.facetec.sdk.** { *; }

I've also tried to use https://github.com/kezong/fat-aar-android library and imported facetec-sdk module as embed project, but build command showed lint error

enter image description here

Upvotes: 5

Views: 12134

Answers (2)

gyparr
gyparr

Reputation: 15

try to put into dependences in build.gradle:app file this string:

api fileTree(dir: 'libs', include: ['*.aar'])

Upvotes: 1

Noamaw
Noamaw

Reputation: 123

I had a similar issue whilst trying to create an android library with a dependency on a SDK that was delivered to me in .aar format. With the newer AGP (Android Gradle Plugin) 4+, not allowing to compile the aar within the android library I was creating - showing me this error: "Direct local .aar file dependencies for a library module are not supported when creating an AAR for the library module.."

I was able to find this link https://www.programmersought.com/article/63808911660/ with an answer that helped deeply, and which gave me the solution to also compile the aar, and also allow me to import it's classes inside my android library.

cutting short -

  1. Create libs folder, and add /name/.arr file to the libs folder.
  2. In the projects's build.gradle file, under the allprojects scope, under the repositories scope, added
    flatDir {
        dirs 'libs' //this way we can find the .aar file in libs folder
    } 
    
  3. In app's build.gradle under dependencies scope add
api(name: '/name/', ext: 'aar')

It currently works, and I hope there is no issues with it later on, but AS is giving a warning to avoid using flatDirs. but Ive wasted too much time on this issue, If anyone has more insight I'll be happy to receive any.

Upvotes: 3

Related Questions