3

I have a multi module app and I want to implement a aar file on a secondary module. I app module works fine if I implement the aar but I need on my secondary module.

But I'm receiving 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. 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 :features:second-module project caused this error: D:\user\my-app\features\second-module\libs\sdk-v3.0.1.aar

I'm adding libs on flatDir:

repositories {
  flatDir {
     dirs 'libs'
  }
}

And this is how I implementing the SDK:

    implementation fileTree(include: ['sdk-v3.0.1.aar'], dir: 'libs' )
1

3 Answers 3

1

Following Andrei Kuznetsov's advice, we use an embedded maven repo wherever an inattentive vendor provide us an AAR file. While it seems complicated at first, it requires just a few command line instructions and add a couple of xml files to the project.

On macOS it is just a matter of:

  1. Installing mvn via Homebrew

     brew install maven      
    
  2. Creating a directory for the embedded local repository

     cd YOUR_PROJECT_ROOT
     mkdir repo
    
  3. Installing the aar in the repo with a reasonable group ID, artifact ID and version (e.g. com.groupid:artifactid:1.0.0)

     mvn install:install-file -Dfile=<SOURCE_AAR_PATH> -DgroupId=com.groupid -DartifactId=artifactid -Dversion=1.0.0 -Dpackaging=aar -DlocalRepositoryPath=<YOUR_PROJECT_DIR>/repo
    
  4. Add the repository to the project

     // Project's build.gradle
     allProjects {
         repositories {
             ... // Other repos
             maven { url "file://${rootDir}/repo" }
         }
     }
    
  5. Declare the dependency as usual

     // Module's build.gradle
     dependencies {
         ... // Other deps
         implementation("com.groupid:artifactid:1.0.0")
     }
    

That's it.

Just remember to also declare the AAR dependencies it the POM file

    <!-- repo/com/groupid/artifactid/1.0.0/artifactid-1.0.0/pom -->
    <project>
      <groupId>com.groupid</groupId>
      <artifactId>artifactid</artifactId>
      <version>1.0.0</version>
      <dependencies>
        <!-- here -->
      </dependencies>
    </project>
Sign up to request clarification or add additional context in comments.

1 Comment

Very helpful for me.Publish to Local Maven Thanks @sigsegv This flutter plugin do same job. pub.dev/packages/flutter_aar
0

This seems to be a dependency transfer problem.

Currently, your second module has a dependency on the aar by the way of "implementation", and your app module has a dependency on your secend module. Therefore, your app module can't access to the aar.

To fix that, you can let your second module depend on the aar by the way of "api", by which, any module depending on the secend module can access to the aar.

api fileTree(include: ['sdk-behavior-v3.0.1-release.aar'], dir: 'libs' )

2 Comments

The problem here is when I use api or implementation on my secondary module, throw me that error. But when I implement directly on my app module works fine. Unfortunately I need that sdk in my secondary module.
Same issue here.. Did you find any solution ?
0

Change this:

implementation fileTree(include: ['sdk-v3.0.1.aar'], dir: 'libs' )

to this:

compileOnly fileTree(include: ['sdk-v3.0.1.aar'], dir: 'libs' )

1 Comment

While this change will result in a successful build, it will also trigger runtime crashes due to the absence of binaries in the resulting APK file.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.