How to include AAR in React Native Android build?

c-h- picture c-h- · May 9, 2017 · Viewed 10.8k times · Source

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 import it with React Native Android? Thanks!

The error I get is this when compiling:

~\app\android\app\src\main\java\com\grind\GrindModule.java:13: error: package com.estimote.sdk does not exist
import com.estimote.sdk.EstimoteSDK;
                        ^

I've made the following changes:

Create android/app/libs/estimote-sdk.aar.

Create react native native module (I've done this a few times before, it works fine until I try to use the SDK).

android/app/build.gradle

dependencies {
    compile(name:'estimote-sdk', ext:'aar')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

android/build.gradle

...
allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        flatDir {
            dirs 'libs'
        }
    }
}

These are the instructions for including the SDK: https://github.com/Estimote/Android-SDK#installation

https://github.com/Estimote/Android-SDK/blob/master/Docs/manual_installation.md#estimote-sdk-for-android-manual-installation

Answer

Luis Fer Garcia picture Luis Fer Garcia · Feb 25, 2020

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
}