Shubham Bisht
Shubham Bisht

Reputation: 687

How to include AAR in React Native Android?

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 -

  1. react-native - 0.69.1
  2. gradle - 7.4.2
  3. Android Studio Bumblebee - 2021.1.1 Patch 3
  4. openjdk - "18.0.1.1" 2022-04-22

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

Answers (2)

Deepak Singh
Deepak Singh

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

Lucifer
Lucifer

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

Related Questions