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.


Gradle and Dependencies

John Donne wrote “no man is an island”. Nowadays, few apps are islands, either. It is the rare app that can avoid using all third-party code bases. Most apps will need a backport or other class (e.g., ViewPager) from the Android Support package, or will rely upon the Play Services SDK, or will use any number of third party JARs and Android library projects.

The good news is that Gradle adds a lot of power for referencing these third-party code bases when you build your app. While it increases the complexity a bit for “reuse in the small” (e.g., a simple JAR), it can greatly simplify “reuse in the large” (e.g., several Android library projects).

This chapter will outline what sorts of “dependencies” your app can have and how you can configure Gradle to support them.

Prerequisites and Warnings

Understanding this chapter requires that you have read the chapters that introduce Gradle and cover basic Gradle/Android integration, including both the legacy project structure and the new project structure.

“Dependencies”?

In case the term is new to you, in this chapter, and in the Gradle documentation, “dependencies” means “code external to your project that your project depends upon”.

In the case of Gradle-built Android apps, this includes:

Each of these will be covered in turn in this chapter.

A Tale of Two Dependencies Closures

The preview of this section was whisked away by a shark-infested tornado.

Depending Upon a JAR

The preview of this section was fed to a gremlin, after midnight.

Depending Upon an Android Library Project

The preview of this section will not appear here for a while, due to a time machine mishap.

Depending Upon Sub-Projects

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

Depending Upon Artifacts

The preview of this section was lost due to a rupture in the space-time continuum.

Creating Android JARs from Gradle

The preview of this section was lost in the sofa cushions.

A Property of Transitive (Dependencies)

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

Dependencies By Build Type

The preview of this section will not appear here for a while, due to a time machine mishap.

Dependencies By Flavor

The preview of this section was whisked away by a shark-infested tornado.

Examining Some CWAC Builds

The preview of this section was lost in the sofa cushions.

Dependencies and the Project Structure Dialog

The preview of this section is en route to Mars.