Reputation: 687
In my React Native Android project, I want to use my own library which has a AAR file. Can someone please guide on how to use the AAR file in my Android build.
Below are my configurations -
And I'm getting below error when creating build -
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 :library-name project caused this error**
Upvotes: 1
Views: 9238
Reputation: 1145
Copy the library.aar
file into react-native-module-name/android/app/libs
. Create the libs
folder if it doesn't exist.
In react-native-module-name/android/app/build.gradle
:
dependencies {
implementation fileTree(dir: "libs", include: ["*.aar"])
implementation 'com.facebook.react:react-native:+' // From node_modules
}
Upvotes: 3
Reputation: 164
Use this in "react-native-module-name/android/app/build.gradle":
dependencies {
implementation fileTree(dir: "libs", include: ["*.aar"])
}
Copy the .aar files into "react-native-module-name/android/app/libs"
As this solution is not working You can do this -
Remove the library from /libs and add it using -
File -> New -> New Module -> Import .JAR/.AAR
Create a new directory and put the following dependencies in build.gradle
dependencies {
implementation project(":imported_aar_module")
}
Place the .aar file here to next directory, next to build.gradle file
Add the created Gradle project to the settings.gradle -
include(":pathToTheCreatedDirectory")
Include the file into the directory -
implementation project(":pathToTheCreatedDirectory",
configuration = "default")
Upvotes: 0