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' )
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:
Installing mvn via Homebrew
brew install maven
Creating a directory for the embedded local repository
cd YOUR_PROJECT_ROOT
mkdir repo
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
Add the repository to the project
// Project's build.gradle
allProjects {
repositories {
... // Other repos
maven { url "file://${rootDir}/repo" }
}
}
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>