Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Expert Android Programming
Expert Android Programming

Expert Android Programming: Master skills to build enterprise grade Android applications

€28.99 €19.99
Book Sep 2017 404 pages 1st Edition
eBook
€28.99 €19.99
Print
€37.99
Subscription
€14.99 Monthly
eBook
€28.99 €19.99
Print
€37.99
Subscription
€14.99 Monthly

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Sep 29, 2017
Length 404 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781786468956
Vendor :
Google
Category :
Table of content icon View table of contents Preview book icon Preview Book

Expert Android Programming

Understanding the Gradle System

Google introduced Gradle and Android Studio in order to help make the development process more streamlined. They wanted to ensure that it becomes easier for developers to reuse code and also help them create build variants with ease. Having it closely integrated with an IDE such as Android Studio ensured that Gradle has a good IDE integration without making the build system dependent on the IDE.

In this chapter, we will discuss:

  • Setting up Gradle in Android Studio
  • Dependent libraries to be used in Android Studio, including Identifiers

If you have been using Eclipse, it's likely that some of you won't know of any alternative to the default APK generation technique within the IDE. But, as such as alternative, you can do this using the command line. The Android build system compiles app resources and source code, and packages them into APKs that you can test, deploy, sign, and distribute.

Stepping into the Gradle world

Gradle is an open source build automation system that is based on the Apache ANT and Maven concept. It introduces a Groovy-based Domain Specific Language (DSL) instead of the XML which is primarily used by Apache Maven for declaring the project configuration. Gradle was designed keeping in mind the support for multi-project builds which grow to be quite a large size, and it supports incremental builds. Gradle does this by understanding which parts of the build tree are up to date.

This ensures that tasks dependent on those parts will not be re-executed. Gradle determines which tasks need to be run and in which order, using Directed Acyclic Graph (DAG).

Gradle can automate the building, testing, publishing, deployment, and more of software packages or other types of projects. Using the combination of the power and flexibility of ANT and the dependency management and conventions of Maven, Gradle helps to build in a more effective manner.

First, let's get familiarized with the Gradle environment inside Android Studio. To do that we should first create a new Android Project. I assume you have Android Studio installed by now. Here is the link in case you wish to know more about the install: https://developer.android.com/studio/install.html

Now that you have the Android Studio installed, we will first create a new project,

Open Android Studio, create a New Project, and give a name to your project as seen in the following figure:

At the Target Android Devices screen, without making any changes, just click on Next:

Next, at the Add an Activity to Mobile screen, select the Empty Activity option for now:

Now, the Activity and an XML file will be generated by default. Just click Finish when done:

When the project load is complete, just change the view structure to Project. You may leave it at Project Files by default:

Once this is done open the build.gradle file. Here you will see the libraries that are compiled in the project:

We have completed the launch of a blank project and we now should understand the basic setup of the same. In the next section, we will talk about adding Gradle to this app.

Adding Gradle to your app

You can Gradle build script dependency to your app in the following way:

Open the file from your app module.

Here, in the dependencies, add the Gradle identifier for a library that you want to import:

Let us consider the current Gradle library, for instance:

com.android.support:appcompat-v7:23.1.1

The components of this Gradle library could be distributed in sections to ease understanding. Here are a few pointers to make note of:

  • com.android.support is the package name of the project
  • appcompat-v7 is the project name
  • 23.1.1 is the version of the project

We have now completed the setup for Gradle in Android Studio. We will be using several libraries in our App. In the next section, we will see how to add new Gradle Libraries.

Adding a new Gradle library

Making Android Development more awesome, Gradle allows us to incorporate libraries in to Android Studio in different ways. Using these, developers can easily include their libraries using Gradle dependencies. In this section we will discuss the following techniques:

  • Adding a Gradle identifier
  • Adding as a module

Adding a Gradle identifier

To add a new Gradle library, find the Gradle identifier for the third party library, and add it to the dependencies list.

When you make changes to the build configuration files in your project, Android Studio requires that you sync your project files so that it can import your build configuration changes and run some checks to make sure your configuration won't create build errors.

To sync your project files, click Sync Now (as seen in the following figure) in the notification bar (this appears when you make a change), or click Sync Project from the menu bar. If Android Studio notices any errors with your configuration--for example, if your code uses API features that are only available in an API level higher than your compileSdkVersion-- the Messages window appears to describe the issue:

Next, we will discuss how libraries can be added using a module.

Adding as a module

You can also add a library in Android Studio by adding it as a module. To add the module:

  1. First, place the library code in any folder of your choice
  2. Then, you need to Import the library as a module in your app. The figure below shows the steps to add the library as a Module:

This will open a new window where you need to select the library that you have saved to the directory. When you have selected the directory, click on Done. This will import the external library into your project.
As an example, I have added the module crop image to my project, which appears in my project folder.

Next, we need to add the module to the app's dependency list. To do this, right click on the module that has been added and click on the Open Module Settings option:

It will open a new window with your app module and library module in the list. Choose you app module, and then select the dependency list.

Next, click on the plus icon which will open another dialog with the module name. Select it and click OK:

This will build the Gradle and add the module to the build.gradle, and it will be seen as a compiled project here:

Note that Core, UI and Util sub projects can also have their own build.gradle file, depending on their specific needs. Alternatively, you can also define the dependencies of a project in the root build.gradle file, as discussed in the preceding section. In this case, we won't be focusing on these points.

Summary

We started the chapter by looking at what Gradle is and how it is important in project development. We briefly looked at the Android Studio setup and how it can help in building the system along with Gradle. After the introduction, we talked about how developers can set up Gradle in Android Studio. We also created a new project in Android and discussed how Gradle libraries can be added to the project.

In Chapter 2, Exploring Android Studio Developer Tools we will discuss some of the key developer tools in Android Studio.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • -Dive deep into Android development with practical hands on examples to help you in each stage.
  • -Develop smart professional grade apps for the latest Android N version and become a pro android developer.
  • -Unclog your development highway by utilising the industry standard best practices techniques.

Description

Android O brings a number of important changes for the users as well as the developers. If you want to create smart android applications which are fast, lightweight and also highly efficient then this is the book that will solve all your problems. You will create a complex enterprise grade app in this book. You will get a quick refresher of the latest android SDK and how to configure your development environment. Then you will move onto creating app layouts, component and module building, creating smart and efficient UIs. The most important part of a modern day app is how real time they are. With this book, you will create a smooth back-end for your app, ensure dynamic and real time communication between different app layers. As we move on, you will learn to leverage the different Android APIs and create an efficient SQLite data layer for your apps. You will implement effective testing techniques to make your app reliable and robust and finally you will learn to deploy it efficiently. The multiple stages of android development will also be simplified by giving you an industry standard set of best practices.

What you will learn

? Building UI/UX following best industry practices ? Development of Zomato Clone ? Measure and improve app performance ? Improving app using test mechanisms ? Bringing the app live on the play store

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Sep 29, 2017
Length 404 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781786468956
Vendor :
Google
Category :

Table of Contents

17 Chapters
Preface Chevron down icon Chevron up icon
Understanding the Gradle System Chevron down icon Chevron up icon
Exploring Android Studio Developer Tools Chevron down icon Chevron up icon
Leap into the Android Support Library Chevron down icon Chevron up icon
Google Play Services Chevron down icon Chevron up icon
Material Design Chevron down icon Chevron up icon
SOLID Android Development and Its Design Principles Chevron down icon Chevron up icon
Understanding MVC, MVP, MVVM and Clean Arch Patterns Chevron down icon Chevron up icon
Decision Making Chevron down icon Chevron up icon
Performance Matters Chevron down icon Chevron up icon
Building Restaurant finder Chevron down icon Chevron up icon
Backend Service Chevron down icon Chevron up icon
App Quality Service Chevron down icon Chevron up icon
Grow Up Chevron down icon Chevron up icon
Testing Chevron down icon Chevron up icon
Preparing for Google Play Chevron down icon Chevron up icon
Understanding App Store Analytics for Optimization Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.