【问题标题】:How to use local aar dependency?如何使用本地 aar 依赖?
【发布时间】:2015-03-05 02:56:58
【问题描述】:

我google了一下本地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'

如何做到这一点?

【问题讨论】:

标签: android android-gradle-plugin aar


【解决方案1】:

我遇到了同样的错误。

这是唯一对我有帮助的事情:

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

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

【讨论】:

  • 这对我有帮助。谢谢
【解决方案2】:

在我的情况下,必须分发 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-08-23
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多