How do I enable AAR in React Native Android build?

I am trying to include an AAR file with my Android React Native app so that I can access its functionality with native code. How can I bind the AAR so that native code can import it using React Native Android? Thank!

The error I am getting is 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 made the following changes:

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

.

Create a reactive native custom 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 enabling 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

+3


source to share


2 answers


There were two ways I chose to enable AAR for compilation.

The SDK specific way to evaluate was to add this line to android/app/build.gradle

:

dependencies {
    ...
     compile 'com.estimote:sdk:1.0.3:release@aar'
}

      

Please note, the documentation was out of date for me for the released SDK version, so it was difficult to figure out which classes and methods to use.

The other way I got the AAR included in the build was the following changes:



The created folder android/libs

, place the AAR file in 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, I can start importing classes and methods.

+1


source


I have tried many ways,

OPEN THE FALL WITH ANDROID STUDIO AND ONLY ADD AAR OR JER

The easiest way is to open the generated folder inside the responding native project using android studio. They add aar as adding aar to a regular project.

enter image description here



enter image description here

In android Studio add as always (Friendly Remainder):

  • Open the module settings (right click on the project)
  • Aar / jar import
  • Add depending
+1


source







All Articles