Reader small image

You're reading from  Mastering Android Studio 3

Product typeBook
Published inAug 2017
Reading LevelIntermediate
Publisher
ISBN-139781786467447
Edition1st Edition
Languages
Right arrow
Author (1)
Kyle Mew
Kyle Mew
author image
Kyle Mew

Kyle Mew has been programming since the early '80s and has written for several technology websites. Also, he has written three radio plays and four other books on Android development.
Read more about Kyle Mew

Right arrow

Packaging and Distribution

Compiling and building APKs is something we do many times during the course of an application's development, and other than including various dependencies, we have taken our build automation system, Gradle, pretty much for granted. Despite this, it will not have escaped the reader's attention that what Gradle actually does is really quite sophisticated and complex.

One of the reasons that we can take Gradle for granted is the way that it configures each build using a process known as convention over configuration. This ensures that, in nearly all cases, Gradle selects the most sensible configuration options for each project. It is when we override these settings that Gradle becomes interesting and useful. For example, we can use it to build mobile and tablet versions of an app from the same Studio project.

Producing a compiled APK file is by...

Gradle build configurations

As the reader will have seen, Gradle scripts generally have a single project (or root) file and one or more module level files:

Gradle scripts

We are told not to edit this file in comments in the root script; unless we have configuration options common to all modules, this is best left as-is.

Module-level scripts are of far more interest to us and the following is a breakdown of a typical one.

The first line simply declares the use of the Gradle plugin:

apply plugin: 'com.android.application'

Next, Android-targeted API level and build tools versions are declared:

android { 
    compileSdkVersion 27 
    buildToolsVersion "27.0.0" 

The default configuration settings define elements of the Android manifest file, and editing them here will be automatically reflected in the manifest after the next build or sync, as follows:

defaultConfig...

An APK analysis

APK Analyzer is one of the handiest features of Android Studio; as its name suggests, it allows us to analyze APK files themselves, even performing a certain amount of reverse engineering by extracting resources and XML and allowing us to compare different versions.

The APK Analyzer can also be found in the Build menu, under Analyze APK.... Every time we run a project on a device or emulator, a debug APK is generated. This can be found in your project directories under; \SomeProject\App\build\outputs\apk\debug.

The Analyzer displays its output, as follows:

APK analysis

The Analyzer's output contains a wealth of information, beginning with its size and its compressed Play store size. It is possible to see at a glance which resources take up the most room and rectify this where possible, for example by using vectors instead of bitmaps.

The classes.dex file...

Publishing applications

Developing a mobile application, even a relatively simple one, is a lengthy process, and once we have tested all our code, ironed out any bumps, and polished our UI, we want to be able to get our product on the shelf as quickly and simply as possible. Android Studio has all these processes incorporated into the workspace.

As the reader will know, the first step toward publication is generating a signed APK.

Generating a signed APK

All Android applications require a digital certificate before they can be installed on a user's device. These certificates follow the usual pattern of including a public key with every download that corresponds with our own private key. This process guarantees authenticity...

Summary

The production of a signed APK is the final step in what will have been a long journey. Beginning with nothing more than an idea, each application will have grown through countless cycles of design, development, and testing before finally being placed on a shelf in a store such as Android Play Store.

Android Studio has been designed to assist developers on every step of this journey, and one of the reasons that Google has put so much into the product; is because, by investing in the developers of the future and making it easier for them to put ideas into practice, the Android platform can only become better.

In this book we have explored the only IDE created specifically for Android development, and we have seen how this specialized approach provides many benefits to the developer. The visual and intuitive nature of the Layout Editor and the way that Constraint Layouts...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Android Studio 3
Published in: Aug 2017Publisher: ISBN-13: 9781786467447
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime

Author (1)

author image
Kyle Mew

Kyle Mew has been programming since the early '80s and has written for several technology websites. Also, he has written three radio plays and four other books on Android development.
Read more about Kyle Mew