How to use local aar dependency?

2019-03-09 20:02发布

问题:

i google about local aar,every one say it can work,but it don't work at android studio 1.1.0.

i try to use :

compile fileTree(dir: 'libs', include: ['*.aar'])

but it tip:

Warning:Project app: Only Jar-type local dependencies are supported. Cannot handle: /Users/kycq/AndroidStudioProjects/QingTaJiao/app/libs/KycqBasic-release.aar

how should i do to use local aar? if i should use:

compile 'com.example.library:library:1.0.0@aar'

how to do this?

回答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



回答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
}