多个 AAR 文件 [英] Multiple AAR files

查看:24
本文介绍了多个 AAR 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Android Studio 1.2

I am using Android Studio 1.2

我创建了一个私有库,我想在另一个应用程序中使用它.

I create a private library I want to use that one in another application.

为了使用它,我创建了一个 AAR 文件,但是这个 AAR 不起作用.我的库中有一个 AAR 文件的依赖项.

To use it I create an AAR files, but this AAR don't work. I have in my library a dependency to an AAR file.

AAR 文件没有依赖关系?

The AAR files do not the dependencies?

如果我使用 jar 并包含 ans 创建所有依赖项,则项目运行良好.

If I use the jar and I includ ans create all the dependencies the project works fine.

注意:

我知道如何导入 AAR 文件.问题是在AAR中使用AAR..

I know how to importe the AAR file. The problem is to use an AAR in the AAR..

谢谢.

推荐答案

如果我对你的问题理解正确,那么涉及到 3 个项目:

If I'm understanding your question correctly, there are 3 projects involved:

库项目 2 --> 库项目 1 --> 应用项目

Library Project 2 --> Library Project 1 --> Application Project

您正在编辑库项目 1",并在其 app/build.grade 中添加了对库项目 2 的 aar 的依赖.像这样:compile 'com.arasthel:gnavdrawer-library:1.1.5'

You are editing "Library Project 1" and have added to it's app/build.grade a dependency on the Library Project 2's aar. Something like this: compile 'com.arasthel:gnavdrawer-library:1.1.5'

我不确定您在哪里遇到问题,但无论如何我都会尝试回答.如果我完全不在基地,您能否详细说明 AAR 依赖项如何不起作用?任何错误消息?,未找到类/资源等.

I am not sure where you are running into an issue, but I'll attempt an answer anyway. If I'm completely off-base, can you please elaborate on how the AAR dependency is not working? Any error messages?, a class/resource not found, etc.

我认为您不太可能无法在 Library Project 1 中使用 Library Project 2 中的类,因为我自己刚刚尝试过,它似乎工作得很好.值得注意的是,Library Project 1 aar 文件将包含来自 Library Project 2 的类或资源.Library Project 2 标记为 Library Project 1 的 pom 中的依赖项,如果使用gradle的maven插件发布Library Project 1.

I think it's unlikely you are unable to use a class from Library Project 2 inside Library Project 1, because I just tried this myself and it seems to be working just fine. It's worth noting that the Library Project 1 aar file will NOT include classes or resources from Library Project 2. Library Project 2 will be noted as a dependency in Library Project 1's pom if published using gradle's maven plugin to publish Library Project 1.

我的猜测是您在应用程序项目中遇到了问题?也许在应用程序项目中找不到库项目 2 中的类?如果这是正确的,那么有两种可能的解决方案:

My guess is that you are having a problem in the Application Project? Perhaps the class from Library Project 2 is not found in the Application Project? If that is correct, then there are two possible solutions:

  1. 在应用程序项目的 app/build.gradle 中启用对 aar 依赖项的传递依赖项:代替 compile 'com.example:myLibrary:versionX',使其成为 compile('com.example:myLibrary:versionX'){transitive=true}.我刚刚验证了这会导致 gradle 读取库项目 1 的 pom 并自动将在那里找到的依赖项添加到应用程序项目中.

  1. Enable transitive dependencies on the aar dependency in the Application project's app/build.gradle: Instead of compile 'com.example:myLibrary:versionX', make it compile('com.example:myLibrary:versionX'){transitive=true}. I just verified this causes gradle to read Library Project 1's pom and automatically add dependencies found there into the Application Project.

如果您想使用传递依赖项,您的库项目将需要生成一个 pom 并将其与 aar 一起发布.请参阅https://stackoverflow.com/a/30085677/431296,了解有关我如何进行这项工作的其他信息.

If you would like to use transitive dependencies, your Library Project will need to be generating a pom and publishing it along with the aar. See https://stackoverflow.com/a/30085677/431296 for some additional information on how I have this working.

手动将库项目 2 的依赖项添加到应用程序项目 - 以便您的应用程序具有两个库的依赖项行.根据您的具体情况,这可能是也可能不是可行的解决方案.

Manually add the dependency on Library Project 2 to the Application Project - so that your Application has a dependency line for both Libraries. Depending on your specific situation this may or may not be a workable solution.

这篇关于多个 AAR 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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