Android .aar依赖项无法在依赖于.aar

时间:2016-12-30 10:14:00

标签: android gradle dependencies android-gradle aar

我在android studio 2.1.3中创建了一个android库AAR,其中我使用了以下依赖项:

compile 'com.google.android.gms:play-services-vision:9.4.0+'
compile 'com.google.android.gms:play-services-wearable:9.4.0+'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'

现在我在应用程序中使用这个aar但是这些依赖项失败了,除非我将它们添加到新应用程序的依赖项中。

我在这里搜索,我发现我需要添加以下行:

compile (project(':LIBNAME-release')) {transitive = true}

但这没有用。有什么我错过了吗?或者它与我对aar文件所做的混淆有关?或者是否必须将这些依赖项添加到应用程序?

2 个答案:

答案 0 :(得分:2)

请按照以下步骤使其正常运行(我已将其测试到Android Studio 2.2)

假设您已将aar文件保存在libs文件夹中。 (假设文件名是cards.aar)

然后在app build.gradle中指定以下内容并单击与Gradle文件同步项目。

allprojects {
   repositories {
      jcenter()
      flatDir {
        dirs 'libs'
      }
   }
}

dependencies {
    compile(name:'cards', ext:'aar')
}

如果一切顺利,您将看到图书馆条目是在构建中进行的 - >分解-AAR

另请注意,如果要从具有依赖项的其他项目导入.aar文件,则还需要在build.gradle中包含这些文件。

go through this link

答案 1 :(得分:0)

首先尝试编译项目:

dependencies {
    compile project(':Name-Of-Your-Project')
}

这是来自that post Ashton Engberg的建议

相关问题