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 abducted by space aliens.

Depending Upon a JAR

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

Depending Upon NDK Binaries

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

Depending Upon an Android Library Project

The preview of this section apparently resembled a Pokémon.

Depending Upon Sub-Projects

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

Depending Upon Artifacts

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

Creating Android JARs from Gradle

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

A Property of Transitive (Dependencies)

The preview of this section left for Hollywood to appear in a reality TV show.

Dependencies By Build Type

The preview of this section took that left turn at Albuquerque.

Dependencies By Flavor

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

Examining Some CWAC Builds

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

Dependencies and the Project Structure Dialog

The preview of this section is in an invisible, microscopic font.