Gradle for Android

Book description

Automate the build process for your Android projects with Gradle

In Detail

Gradle is an open source build automation system that introduces a Groovy-based domain-specific language (DSL) to configure projects. Using Gradle makes it easy for Android developers to manage dependencies and set up the entire build process.

This book begins by taking you through the basics of Gradle and how it works with Android Studio. Furthermore, you will learn how to add local and remote dependencies to your project. You will work with build variants, such as debug and release, paid and free, and even combinations of these things. The book will also help you set up unit and integration testing with different libraries and will show how Gradle and Android Studio can make running tests easier. Finally, you will be shown a number of tips and tricks on the advanced customization of your application's build process. By the end of this book, you will be able to customize the entire build process, and create your own tasks and plugins for your Gradle builds.

What You Will Learn

  • Build new Android apps and libraries using Android Studio and Gradle
  • Migrate projects from Eclipse to Android Studio and Gradle
  • Manage the local and remote dependencies of your projects
  • Create multiple build variants
  • Include multiple modules in a single project
  • Integrate tests into the build process
  • Create custom tasks and plugins for Android projects

Table of contents

  1. Gradle for Android
    1. Table of Contents
    2. Gradle for Android
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Getting Started with Gradle and Android Studio
      1. Android Studio
        1. Staying up to date
      2. Understanding Gradle basics
        1. Projects and tasks
        2. The build lifecycle
        3. The build configuration file
          1. The project structure
      3. Creating a new project
      4. Getting started with the Gradle Wrapper
        1. Getting the Gradle Wrapper
        2. Running basic build tasks
      5. Migrating from Eclipse
        1. Using the import wizard
        2. Migrating manually
          1. Keeping the old project structure
          2. Converting to the new project structure
          3. Migrating libraries
      6. Summary
    9. 2. Basic Build Customization
      1. Understanding the Gradle files
        1. The settings file
        2. The top-level build file
        3. The module build file
          1. Plugin
          2. Android
          3. Dependencies
      2. Getting started with tasks
        1. Base tasks
        2. Android tasks
        3. Inside Android Studio
      3. Customizing the build
        1. Manipulating manifest entries
          1. Inside Android Studio
        2. BuildConfig and resources
        3. Project-wide settings
        4. Project properties
        5. Default tasks
      4. Summary
    10. 3. Managing Dependencies
      1. Repositories
        1. Preconfigured repositories
        2. Remote repositories
        3. Local repositories
      2. Local dependencies
        1. File dependencies
        2. Native libraries
        3. Library projects
          1. Creating and using library project modules
          2. Using .aar files
      3. Dependency concepts
        1. Configurations
        2. Semantic versioning
        3. Dynamic versions
      4. Inside Android Studio
      5. Summary
    11. 4. Creating Build Variants
      1. Build types
        1. Creating build types
        2. Source sets
        3. Dependencies
      2. Product flavors
        1. Creating product flavors
        2. Source sets
        3. Multiflavor variants
      3. Build variants
        1. Tasks
        2. Source sets
        3. Resource and manifest merging
        4. Creating build variants
        5. Variant filters
      4. Signing configurations
      5. Summary
    12. 5. Managing Multimodule Builds
      1. The anatomy of a multimodule build
        1. The build lifecycle revisited
        2. Module tasks
      2. Adding modules to a project
        1. Adding a Java library
        2. Adding an Android library
        3. Integrating Android Wear
        4. Using Google App Engine
          1. Analyzing the build file
          2. Using the backend in an app
          3. Custom tasks
      3. Tips and best practices
        1. Running module tasks from Android Studio
        2. Speeding up multimodule builds
        3. Module coupling
      4. Summary
    13. 6. Running Tests
      1. Unit tests
        1. JUnit
        2. Robolectric
      2. Functional tests
        1. Espresso
      3. Test coverage
        1. Jacoco
      4. Summary
    14. 7. Creating Tasks and Plugins
      1. Understanding Groovy
        1. Introduction
        2. Classes and members
        3. Methods
        4. Closures
        5. Collections
        6. Groovy in Gradle
      2. Getting started with tasks
        1. Defining tasks
        2. Anatomy of a task
        3. Using a task to simplify the release process
      3. Hooking into the Android plugin
        1. Automatically renaming APKs
        2. Dynamically creating new tasks
      4. Creating your own plugins
        1. Creating a simple plugin
        2. Distributing plugins
        3. Using a custom plugin
      5. Summary
    15. 8. Setting Up Continuous Integration
      1. Jenkins
        1. Setting up Jenkins
        2. Configuring the build
      2. TeamCity
        1. Setting up TeamCity
        2. Configuring the build
      3. Travis CI
        1. Configuring the build
      4. Further automation
        1. The SDK manager plugin
        2. Running tests
        3. Continuous deployment
        4. Beta distribution
      5. Summary
    16. 9. Advanced Build Customization
      1. Reducing the APK file size
        1. ProGuard
        2. Shrinking resources
          1. Automatic shrinking
          2. Manual shrinking
      2. Speeding up builds
        1. Gradle properties
        2. Android Studio
        3. Profiling
        4. Jack and Jill
      3. Ignoring Lint
      4. Using Ant from Gradle
        1. Running Ant tasks from Gradle
        2. Importing an entire Ant script
        3. Properties
      5. Advanced app deployment
        1. Split APK
      6. Summary
    17. Index

Product information

  • Title: Gradle for Android
  • Author(s): Kevin Pelgrims
  • Release date: July 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781783986828