13

I am building an Android library that is packaged as an aar and distributed to 3rd party developers.

The structure is pretty simple:

project ---libraryA ---libraryB

libraryA requires libraryB, which is why is has this in its gradle file:

compile project(':libraryB')

And settings.gradle has

include ':libraryB', ':libraryA'

But if I build the project as an aar it only includes libraryA. What am I missing?

I read the responses to this: Android Studio how to package single AAR from multiple library projects?

Is this still not possible? I would assume that splitting up your code into multiple modules is not bad practice?

Community
  • 1
  • 1
Philipp E.
  • 3,296
  • 3
  • 34
  • 52

2 Answers2

9

Is this still not possible?

Correct, at least through the standard build tools. It's possible there are third-party plugins, scripts, or other recipes to create a "fat AAR" out of an AAR and its dependencies.

I would assume that splitting up your code into multiple modules is not bad practice?

Having multiple modules is perfectly fine for local development. However, modules are dependencies. When you ship a library, you need to satisfy all those dependencies, which will include any of your modules. That, in turn, means that any modules that your library depends upon must also be libraries, distributed in a way that a consumer of your top-level library will be able to get to those dependencies.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 2
    can you give an example of a script or third-party plugin that does the work? – Teodor May 13 '15 at 13:25
  • 1
    @Teodor: No, because I have never researched this. That's why I wrote "It's possible that...". These "fat" packages are generally frowned upon, and I personally detest them. However, I know there are things that create fat JARs (though I forget their names), and so in principle something could create a "fat AAR", given sufficient engineering effort. – CommonsWare May 13 '15 at 13:28
7

You can try fat-aar.gradle script published here: https://github.com/adwiv/android-fat-aar

  • Neat, thanks for the tip! These days we just deploy our library through our own maven repository, which works fine for us. But this might come in handy for someone else. – Philipp E. Oct 28 '15 at 10:09
  • 1
    Yes, we used local maven, but maybe someone want distribute aar with embedded libraries. And it would appropriate for the case. – Vladimir Ryhlitskiy Oct 29 '15 at 18:15