The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.

Working with Library Modules

Android library modules are the primary unit of Android source reuse, particularly where that source involves more than just Java source code, such as Android resources.

In this chapter, we will explore the basics of setting up and using an Android library module.


Understanding this chapter requires that you have read the core chapters of this book.

Creating a Library Module

An Android library module, in many respects, looks like a regular Android project. It has source code and resources. It has a manifest.

What it does not do, though, is build an APK file. Instead, it represents a basket of programming assets that the Android build tools know how to blend in with regular Android projects.

Making a project be an Android library module is simply a matter of choosing the right Android Gradle Plugin.

Rather than have:

apply plugin: ''


apply plugin: ''

That’s it — the plugin now knows that it is creating a library, not an app.

The real question is, where are you making this library? In many cases, you will do so as a module in a project, where there is another module that is an app. This covers both:

Adding new modules to an Android Studio project is handled most simply via the new-module wizard, which you can bring up via File > New > New Module… from the main menu. This brings up the first page of the new-module wizard:

Android Studio New-Module Wizard, First Page
Figure 330: Android Studio New-Module Wizard, First Page

To add a library module as a module to an existing project, choose “Android Library” in the list of module types, then click Next to proceed to the second page of the wizard:

Android Studio New-Module Wizard, Second Page
Figure 331: Android Studio New-Module Wizard, Second Page

This collects some bits of information, including:

At this point, clicking Next will take you to the same new-activity flow that you saw when creating a new project. If you want an activity to be generated for you in this library, proceed by selecting the activity template and providing the activity template configuration data. If you do not want an activity, choose “Add No Activity” in the grid of templates, then click “Finish” to create the module.

In the end, the new-module wizard will set up the new module for you, in your designated subdirectory of the project, including modifying settings.gradle to list this subdirectory as being a module within the project. At this point, you will be able to start using the library within the project itself.

Using a Library Module

The preview of this section was accidentally identified as an Android 'tasty treat' by the Cookie Monster.

Library Modules and the Manifest

The preview of this section was the victim of a MITM ('Martian in the middle') attack.

Library Modules and Transitive Dependencies

The preview of this section is presently indisposed.

Limitations of Library Modules

The preview of this section is en route to Mars.