'React Native [0.66.4][Android] - Direct local .aar file dependencies are not supported when building an AAR

I'm using a react-native library, and when I'm trying to Rebuild project on Android Studio, I get the below error -

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**

Although I do have aar file in the android folder of the library I'm using.

I'm using

  1. react-native - 0.66.4
  2. gradle version - 6.9

And below is the build.gradle present in Android folder of library I'm using.


buildscript {
    repositories {
        jcenter()
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.2'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 29

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
}

repositories {
    mavenCentral()
    google()
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.aar'])
    implementation 'com.facebook.react:react-native:0.20.1'

}
  

Edit

Below is the picture of library I've mentioned above. In this library, I'm testing it in _test folder. And _test is just a normal react-native project.

And it's the .aar file inside libs (which is selected in picture) which I've mentioned in above question.

enter image description here



Solution 1:[1]

Try following

  1. Place .aar file to android/app/libs directory
  2. Add following code snippet to app build.gradle (just above dependencies for example)
allprojects {
    repositories{
        flatDir{
            dirs 'libs'
        }
    }
}
  1. Add following to app build gradle dependencies:
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation files('libs/name-of-the-lib.aar')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alvAro365