5

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

Mirian Okradze
  • 335
  • 1
  • 5
  • 9
  • Please refer to this answer: https://stackoverflow.com/a/60888941/3586084 – alierdogan7 Oct 04 '21 at 13:36
  • could you find a solution? I'm using facetec framework and having same issue. – Hashem Aboonajmi Aug 04 '22 at 14:34
  • I've extracted AAR dependency as module (In 2nd picture), uploaded to S3 and used in my project as remote dependency. Sorry, I don't have source code anymore, but you need to upload FaceTec library somewhere and use it from url, not from project directory itself. This may help. https://medium.com/@porten/publishing-android-library-artifacts-to-amazon-s3-buckets-8db4231e844f – Mirian Okradze Aug 14 '22 at 13:03

2 Answers2

4

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.

Noamaw
  • 127
  • 1
  • 4
  • Thanks for the answer. I extracted AAR dependency as module (In 2nd picture), uploaded to S3 like Maven repository and used in my project as remote dependency. – Mirian Okradze Jul 11 '21 at 09:44
  • AAR files are no longer supported under the "lib" directory. You must reference AAR libraries via a "build.gradle" file's dependencies section instead – grebulon Dec 07 '22 at 09:06
1

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

api fileTree(dir: 'libs', include: ['*.aar'])
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
gyparr
  • 15
  • 1