简体   繁体   English

多个AAR文件

[英]Multiple AAR files

I am using Android Studio 1.2 我使用的是Android Studio 1.2

I create a private library I want to use that one in another application. 我创建了一个私有库,我想在另一个应用程序中使用它。

To use it I create an AAR files, but this AAR don't work. 要使用它我创建一个AAR文件,但这个AAR不起作用。 I have in my library a dependency to an AAR file. 我的库中有一个对AAR文件的依赖。

The AAR files do not the dependencies? AAR文件不依赖?

If I use the jar and I includ ans create all the dependencies the project works fine. 如果我使用jar,我包括创建所有依赖项,项目工作正常。

NOTE : 注意 :

I know how to importe the AAR file. 我知道如何导入AAR文件。 The problem is to use an AAR in the AAR.. 问题是在AAR中使用AAR ..

Thanks. 谢谢。

If I'm understanding your question correctly, there are 3 projects involved: 如果我正确理解您的问题,则涉及3个项目:

Library Project 2 --> Library Project 1 --> Application Project 图书馆计划2 - >图书馆计划1 - >应用项目

You are editing "Library Project 1" and have added to it's app/build.grade a dependency on the Library Project 2's aar. 您正在编辑“图书馆计划1”,并已添加到它的app / build.grade对图书馆计划2的aar的依赖。 Something like this: compile 'com.arasthel:gnavdrawer-library:1.1.5' 像这样的东西: compile 'com.arasthel:gnavdrawer-library:1.1.5'

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? 如果我完全偏离基础,你能详细说明AAR依赖是如何工作的吗? Any error messages?, a class/resource not found, etc. 任何错误消息?,找不到类/资源等。

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. 我认为你不可能在图书馆计划1中使用图书馆计划2中的一个类,因为我自己尝试了这个并且似乎工作得很好。 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. 值得注意的是,Library Project 1 aar文件不会包含来自Library Project 2的类或资源。如果使用gradle的maven插件发布Library Project 1,则Library Project 2 被注释为Library Project 1的pom中的依赖项。

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? 也许应用程序项目中找不到Library Project 2中的类? If that is correct, then there are two possible solutions: 如果这是正确的,那么有两种可能的解决方案:

  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} . 在Application项目的app / build.gradle中启用对aar依赖项的传递依赖:而不是compile 'com.example:myLibrary:versionX' ,使其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. 我刚刚验证了这导致gradle读取Library Project 1的pom并自动将其中的依赖项添加到Application Project中。

    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. 如果您想使用传递依赖项,您的图书馆计划将需要生成一个pom并将其与aar一起发布。 See https://stackoverflow.com/a/30085677/431296 for some additional information on how I have this working. 有关如何使用此功能的其他信息,请参阅https://stackoverflow.com/a/30085677/431296

  2. Manually add the dependency on Library Project 2 to the Application Project - so that your Application has a dependency line for both Libraries. 手动将库项目2的依赖项添加到应用程序项目 - 以便您的应用程序具有两个库的依赖项。 Depending on your specific situation this may or may not be a workable solution. 根据您的具体情况,这可能是也可能不是可行的解决方案。

Add following code to you project build.gradle file, and you should put you AAR file to the libs folder. 将以下代码添加到项目build.gradle文件中,您应该将AAR文件放到libs文件夹中。

repositories {
    mavenCentral()
    flatDir {
        dirs 'libs'
    }
}

And finally add compile info to your dependencies: 最后将编译信息添加到您的依赖项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM