在 Android 库项目中包含 AAR 依赖项 [英] Include AAR dependency in Android Library Project

查看:38
本文介绍了在 Android 库项目中包含 AAR 依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android Studio Gradle 项目中,我使用了多个库,而一个库应该使用本地 AAR 文件作为依赖项.我使用流行的解决方案将 AAR 文件作为依赖项包含到我的库项目中:

In my Android Studio Gradle project I use several libraries, whereas one library should use a local AAR file as dependency. I used the popular solution to include the AAR file as dependency into my library project:

flatDir {
    dirs 'libs'
}

compile(name: 'aar-library', ext: 'aar')

当我现在尝试同步时,我收到错误消息

When I now try to sync I get the error message

无法解决:依赖'aar-library'

Failed to resolve: dependency 'aar-library'

在我的主项目中,即使我没有在那里使用/引用 AAR 文件.如果我只是将 AAR 文件复制到我的主项目的 libs 文件夹中,它也可以工作.有什么想法吗?

in my main project even though I'm not using / referencing the AAR file there. If I just copy the AAR file into the libs folder of my main project too it works. Any idea?

推荐答案

已经找到解决方案.看起来 AAR 依赖项都移到了一起,因此主项目尝试在其libs"目录中解析 A​​AR 依赖项,而该目录显然不存在.您需要做的是更准确地定义依赖于带有 AAR 文件的库的每个模块可以相对于其路径找到它的位置,例如

Already found the solution. It looks like the AAR dependencies are all moved together, so the main project tries to resolve AAR dependency in its 'libs' directory, where it obviously does not exist. What you need to do is define more accurately where each module that depends on the library with the AAR file can find it relative to its path, e.g.

dirs project(':my-library-project').file('libs')

这篇关于在 Android 库项目中包含 AAR 依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆