How to use local aar dependency?

Solution 1:

I was getting the same errors.

This was the only thing that helped me:

dependencies {
   compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
 }
repositories{
      flatDir{
              dirs 'libs'
       }
 }

Reference: Adding local .aar files to Gradle build using "flatDirs" is not working

Solution 2:

In my case a have to distribute an aar. When i import the aar in another project this error appears. I solve this problem distributing the aar with a maven dependency structure (pom, md5, etc...)

publishing {
  publications {
    maven(MavenPublication) {
      groupId "<GROUP_ID>"
      artifactId "<ARTIFACT_ID>"
      version <VERSION>
      artifact "$buildDir/outputs/aar/<AAR_FILE>"
      pom.withXml {
        def dependenciesNode = asNode().appendNode("dependencies")
        configurations.compile.allDependencies.each { dependency ->
          def dependencyNode = dependenciesNode.appendNode("dependency")
          dependencyNode.appendNode("groupId", dependency.group)
          dependencyNode.appendNode("artifactId", dependency.name)
          dependencyNode.appendNode("version", dependency.version)
        }
      }
    }
  }
  repositories {
    maven {
      url "$buildDir/repo"
    }
  }
}

On the android application i need to add the local maven repository:

allprojects {
  repositories {
    jcenter()
    maven {
      url "<LOCAL_REPO>"
    }
  }
}

And add the dependency:

compile("<GROUP_ID>:<ARTIFACT_ID>:<VERSION>@aar") {
  transitive = true
}