Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include an Android library module in another library?

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?

like image 462
Philipp E. Avatar asked Dec 15 '14 14:12

Philipp E.


People also ask

Can we import module from source in Android Studio?

Select the source directory of the Module you want to import and click Finish. Open Project Structure Dialog (You can open the PSD by selecting File > Project Structure) and from the left panel click on Dependencies. Select the module from the Module(Middle) section In which you want to add module dependency.


2 Answers

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.

like image 146
CommonsWare Avatar answered Oct 17 '22 08:10

CommonsWare


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

like image 7
Vladimir Ryhlitskiy Avatar answered Oct 17 '22 07:10

Vladimir Ryhlitskiy