【问题标题】:Android .aar dependencies aren’t resolving in app project that depends on .aarAndroid .aar 依赖项在依赖 .aar 的应用程序项目中未解决
【发布时间】:2017-05-14 15:31:59
【问题描述】:

我在 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 文件所做的混淆有关?还是必须将这些依赖项添加到应用程序中?

【问题讨论】:

    标签: android gradle dependencies android-gradle-plugin aar


    【解决方案1】:

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

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

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

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

    如果一切顺利,你会看到库条目是在 build -> exploded-aar

    另外请注意,如果您从另一个具有依赖项的项目中导入 .aar 文件,您也需要在 build.gradle 中包含这些文件。

    go through this link

    【讨论】:

    • 那么我还需要在另一个项目中添加依赖项。感谢您的回复
    【解决方案2】:

    尝试先编译你的项目:

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

    这是 Ashton Engberg 的来自that post 的建议

    【讨论】:

    • 这是我现在使用的。但该项目要求我在 aar 中使用的依赖项。除了 aar 之外,我还应该在应用程序中使用依赖项吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 2018-04-02
    相关资源
    最近更新 更多