6

For various reasons I am in a situation where I have multiple app components existing in small isolated android-library projects, which are being compiled out as .aars.

In some cases these are pushed to a maven repo and consumed that way, which is fine and everything works great.

In other cases these aars need to be compiled into another android library. With my current config Im having issues as the child aar lib contents are not added to the parent aar lib project on gradlew assembleRelease.

Dependency flow is like

Apk app project -> parentLibProject -*> childLibProject

This results in the parent aar compiling fine as the child aars are on the classpath but will not include the child aar libs contents in the output parent aar. This means any android application project which uses the parent lib will fail at compilation time as the child lib aar files/code are not in the parent aar. I do not want to go the route of forcing the app project to manually list all the child lib projects that have already been listed in the parent lib project. In essence I want to aars to be treated in a similar way to jar libs that are used by a library project i.e. compiled into the output aar.

I have tried a few non-successful approaches (which all build fine but all fail to output the child aar lib contents into the parent aar lib file):

  1. The compiled child aar inside /libs/, which is on declared in the repository closure with flatDir { dirs 'libs' } and imported to parent lib project with compile(name:'someAarLib-x.y.z', ext:'aar'). This compiles fine but the parent project will also need to include the someAarLib-x.y.z aar and compile(name:'someAarLib-x.y.z', ext:'aar').
  2. Importing the child aar as modules as described in this answer https://stackoverflow.com/a/24894387/236743. This compiles fine but has the same problem as 1.
  3. Using the same approach as https://stackoverflow.com/a/33264652/236743 but with *.aar. This does not work at all (as commented elsewhere on SO)

I am using Gradle 2.3 and android plugin 1.2.1 at present.

For now I am doing it in a hacky way of pulling the classes.jars out of the child aar projects and putting the the parent lib project (as per https://stackoverflow.com/a/33264652/236743) as it just so happens that they dont use any xml resources so Im not losing anything in this case. But this is slightly time consuming and not very scalable / bit of manual work I dont want to do. Yes could automate this but im sure there is an offical way that I have just not stumbled across the correct config.

Many thanks for any help.

Community
  • 1
  • 1
Dori
  • 18,283
  • 17
  • 74
  • 116
  • It is not so clear what is the issue. Using aar files, you have to configure the maven to tell about flatdir, and you have to add a compile line in the dependency block. – Gabriele Mariotti Oct 22 '15 at 10:09
  • Yes I am aware of that - have updated the question to be clearer about the issue. What you are suggesting sounds the same as no **1** above, which does not solve the problem. – Dori Oct 22 '15 at 15:08
  • The parent project aar will not contain the nested dependencies. It means that the parent aar will not contain the aar-child and the child dependencies. Check also: http://stackoverflow.com/questions/32656906/how-to-bundle-a-dependencys-resources-along-with-my-own-aar/32658383#32658383 – Gabriele Mariotti Oct 22 '15 at 15:30
  • Thanks for the reply. I know it will not by default (thats why I am asking) but am wondering if there is a way to make it so. It would be the same resolution/merge process as when an apk pulls in a aar files resources at build time so Im assuming I just have not hit upon the right config to make this happen (rather than it not being possible) – Dori Oct 22 '15 at 16:52
  • @Dori: Did you got any solution on this? – ImMathan May 23 '16 at 12:42
  • Nothing extra to add to the above no. – Dori May 25 '16 at 09:43

0 Answers0