47

我在谷歌上搜索了本地 aar,每个人都说它可以工作,但它在 android studio 1.1.0 上不起作用。

我尝试使用:

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

但它提示:

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

我应该如何使用本地 aar?如果我应该使用:

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

这个怎么做?

4

2 回答 2

70

我遇到了同样的错误。

这是唯一帮助我的事情:

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

参考:使用“flatDirs”将本地 .aar 文件添加到 Gradle 构建不起作用

于 2015-05-13T16:27:02.277 回答
6

在我的情况下,必须分发 aar。当我在另一个项目中导入 aar 时,会出现此错误。我解决了这个问题,使用 maven 依赖结构(pom、md5 等)分发 aar

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"
    }
  }
}

在 android 应用程序上,我需要添加本地 maven 存储库:

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

并添加依赖:

compile("<GROUP_ID>:<ARTIFACT_ID>:<VERSION>@aar") {
  transitive = true
}
于 2016-04-14T14:13:35.270 回答