Book Image

Android Application Development with Maven

Book Image

Android Application Development with Maven

Overview of this book

Table of Contents (14 chapters)

Preface

During the months we were writing this book, a lot of people asked us what would make this book special and why someone should care to read it. The most powerful argument that I heard all this time was, "Hey, Google official supports only Gradle to build Android applications and the latest release of Android Studio makes extensive use of Gradle. Ant was already replaced and Maven is nowhere. Why do you spend time writing about developing Android applications with Maven?"

Good questions! The answers, however, is hidden within the question itself. First of all, there are no books out there that explain step by step about all the development phases and critical tasks to build and manage the life cycle of an Android Application with Maven. Maven is still—no matter if we like it or not—the most popular build tool. Many "traditional" software houses that have invested time and efforts to standardize their development process around Maven want to make the next step and expand their portfolio to the Android Market. Clearly, having another build tool only for Android development doesn't look very practical, although it's an option.

Companies would save a lot of money if they could just plug their Android applications to the existing development life cycle, driven by Maven. At the same time, it's true that Maven is a very mature, flexible, and robust build tool. Its extensibility through plugins and the idea of descriptively configuring the build process without the need to write scripts made it the de-facto standard.

The reality, however, has shown us that it's not always that easy. Maven provides all the required plugins to do almost everything, but there are no instructions or well-structured documentation. You can find blog posts here and there that shortly cover some topics but this is not enough.

This book aims to fill that gap. It will not teach you how to write Android applications, although you will find some simple examples. It will guide you, however, from A to Z, about how to set up all the necessary Maven configuration to compile, run, test, deploy, release, and verify the quality of an Android application. It's convenient for both experienced and young Android developers because we provide all the example code to see Maven in action. This book is also for those of you who already have some Maven experience but feel lost when you try to integrate it with your Android development process.

You can read the book sequentially if you have little experience with Maven, but you can also use it as a reference and jump to any chapter you want as each one is dedicated to a particular topic. The provided code is separated in different folders per chapter so that you can easily run the examples and verify that you have correctly followed the instructions of the book.

We are confident that you will find the book useful and practical, and we hope that it will help you build your next Android application with Maven.

What this book covers

Chapter 1, Beginning with the Basics, introduces you to the basic concepts of Maven and guides you to install all the required software you need to develop an Android application with Maven.

Chapter 2, Starting the Development Phase, sets the pace for the rest of the book. It discusses the first step to set up a minimal Maven configuration to compile and deploy an Android application to a real device or emulator.

Chapter 3, Unit Testing, covers several ways to write and run unit tests using various tools. It also explains the differences between unit and integration testing and the important role that both of them playing when developing an Android application.

Chapter 4, Integration Testing, completes the discussion about testing and presents three alternatives of running Android instrumentation tests, and also provides guidance on properly configuring Maven.

Chapter 5, Android Flavors, discusses the hot topic of maintaining multiple versions (free, ads-supported, and paid) of the same application. It describes the problem and then presents two ways to handle the case using Maven.

Chapter 6, Release Life Cycle and Continuous Integration, is all about releasing and deploying an Android application to a Maven repository. A bonus topic in this chapter discusses about automating everything using Jenkins, the most popular continuous integration engine.

Chapter 7, Other Tools and Plugins, is the last chapter and covers two very important topics: code quality with SonarQube and speeding up the development life cycle using the non-standard emulators provided by Android.

What you need for this book

This book is about software development, so you will need to install some tools in order to follow the examples and practices discussed. You can use almost all operating systems (Windows, Linux, and Mac OS) to run the code included in this book as most of the commands you will see run in a terminal window. All the other software required is covered mostly in Chapter 1, Beginning with the Basics, where we set up our development environment (SDKs, IDEs, and so on) so you don't need to pre-install anything. This also applies to the rest of the chapters when we demonstrate the integration of Maven with other popular tools. In general, don't worry if you don't have anything installed yet. We will guide you step by step. On the other hand, if you find yourself reading instructions about installing software you already have in your environment, feel free to skip it.

Who this book is for

Android Application Development with Maven is intended for Android developers or devops engineers who want to use Maven to effectively develop quality Android applications. Whether you are already using Maven or another build tool, this book focuses only on Maven topics that are related to the Android development. It would be helpful, but not necessary, if you have some previous experience with Maven.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "A folder target containing a chapter1.apk archive should be created."

A block of code is set as follows:

public class BookServiceImpl implements BookService {
  @Override
  public Book createBook(String title, String format, String color, Integer numberOfPages) {
    final Book book = new Book();
    book.setTitle(title);
    book.setFormat(format);
    book.setColor(color);
    book.setNumberOfPages(numberOfPages);
    return book;
  }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<dependency>
  <groupId>${project.groupId}</groupId>
  <artifactId>contract</artifactId>
  <version>1.0-SNAPSHOT</version>
  <type>pom</type>
</dependency>

Any command-line input or output is written as follows:

$ANDROID_HOME//tools/android move avd --name Nexus_7_2012 --rename Nexus_7_2012_bis

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Clicking the Next button moves you to the next screen."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.