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 the New Project Structure

A previous chapter showed how you can use Gradle, and the Android Plugin for Gradle, to do command-line builds of projects that can also work with Eclipse, IntelliJ IDEA, Ant, etc.

However, while the legacy project directory structure works, it does not let you leverage the full power of the Android Plugin for Gradle. To take advantage of the build flexibility of the new build system, you will need to organize your source, resources, assets, and related files somewhat differently.

This chapter will outline this “new project structure” and show you how the Android Plugin for Gradles’s concepts of build types and product flavors will make it easier for you to have multiple different forms of output from a single, albeit reorganized, project tree. This project structure is native to Android Studio, so Android Studio projects are already set up to be able to support these sorts of advanced capabilities.

Prerequisites and Warnings

Understanding this chapter requires that you have read the chapters that introduce Gradle and cover basic Gradle/Android integration, in the context of covering the use of Gradle with the legacy project structure.

Objectives of the New Project Structure

In the beginning, Android apps tended to be pretty simple, as we only had a handful of devices, a smattering of users, one primary distribution channel (the then-Android Market) and few major investors in the Android ecosystem.

Times have changed.

Now, Android apps for public consumption can be terribly complex, let alone apps for internal enterprise use (which seem to be complex as a side effect of being developed by an enterprise). We have multiple distribution channels, such as the Amazon AppStore for Android and Yandex.Store. We have a billion devices and nearly a billion users. Brands large and small are flocking to Android, bringing with them their own challenges.

The new build system is designed to simplify creating complex Android applications, while, ideally, not making simple Android applications a lot harder. It is designed for scenarios like:

The new project structure, coupled with the Android Plugin for Gradle and Gradle itself, makes all of this possible… albeit with a bit of a learning curve.

Terminology

The preview of this section is presently indisposed.

Creating a Project in the New Structure

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

What the New Project Structure Looks Like

The preview of this section is [REDACTED].

Configuring the Stock Build Types

The preview of this section is [REDACTED].

Adding Build Types

The preview of this section is presently indisposed.

Adding Product Flavors and Getting Build Variants

The preview of this section may contain nuts.

Doing the Splits

The preview of this section may contain nuts.

Revisiting the Legacy Gradle File

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

Working with the New Project Structure in Android Studio

The preview of this section was eaten by a grue.

Flavors, Build Types, and the Project Structure Dialog

The preview of this section is presently indisposed.