Multiple AAR files

不打扰是莪最后的温柔 提交于 2019-12-29 07:47:07

问题


I am using 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. I have in my library a dependency to an AAR file.

The AAR files do not the dependencies?

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

NOTE :

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

Thanks.


回答1:


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

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

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'

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.

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.

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. 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.

    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.




回答2:


Add following code to you project build.gradle file, and you should put you AAR file to the libs folder.

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

And finally add compile info to your dependencies:

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


来源:https://stackoverflow.com/questions/30052058/multiple-aar-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!