I\'m trying to include an AAR file with my React Native Android app so that I can access its features using native code. How can I bundle an AAR so that native code can impo
There were two ways I figured out to include an AAR for compilation.
The Estimote SDK specific way was to add this line to android/app/build.gradle
:
dependencies {
...
compile 'com.estimote:sdk:1.0.3:release@aar'
}
Note, the documentation was out of date for me for the released version of the SDK, so it was tricky figuring out what the classes and methods to use were.
The other way I got AARs included in the build was the following changes:
Created folder android/libs
, put the AAR file inside of it.
In android/app/build.gradle
:
fileTree(dir: 'libs', include: '**/*.aar')
.each { File file ->
dependencies.add("compile", [
name: file.name.lastIndexOf('.').with { it != -1 ? file.name[0..<it] : file.name },
ext: 'aar'
])
}
With that done I could start importing the classes and methods.
I tried many ways,
OPEN FOLDER WITH ANDROID STUDIO AND JUST ADD THE AAR OR JAR
The easiest way was to open the generated folder inside de react native project with android studio. Them add the aar as adding the aar to a regular project.
In android Studio add as always (Friendly Remainder):
Copy the library.aar
file into react-native-module-name/android/libs
. Create the libs
folder if it doesn't exists.
In react-native-module-name/android/build.gradle
:
dependencies {
implementation fileTree(dir: "libs", include: ["*.aar"])
implementation 'com.facebook.react:react-native:+' // From node_modules
}