Insider's Guide To Udacity Android Developer Nanodegree Part 4 - Build it Bigger
Written by Nikos Vaggalis   
Monday, 02 October 2017
Article Index
Insider's Guide To Udacity Android Developer Nanodegree Part 4 - Build it Bigger
Build It Bigger Project
Getting to Endpoints
Putting it all together

Steadily advancing through the Android Developer Nanodegree, I've now reached Level 3 on the curriculum, "Gradle for Android and Java" in which students learn how to use Gradle to "turn a pile of source code and resources into a shipped,tested and functioning app".

Tools which automate a project's build process have become an essential part of any developer's toolchain, considering that nowadays the making of an application is not just constrained to writing code.There's also other accompanying tasks that should be run in parallel.Some of those are identifying and bundling dependencies, copying resources such as images and strings, running unit tests, diversifying through product flavors, minifying or obfuscating the source, handling signing keys, packing a jar or apk and deploying the finished product to a repository or even publishing it to Google Playstore.

Trying to follow a sequence and manual tracking of all those tasks as well as repeating them when deemed necessary, translates into decreased productivity forasmuch as the time lost on such tedious procedures, that could otherwise be automated, could have been funnelled to other activities such as coding, developing and improving the overall quality of the end product instead.

Fortunately there's dedicated build tools for that, Ant, Maven (for a rundown on building projects with Maven make sure to check my recent Hardcore DevOps article) and Gradle, the latter being considered the more advanced post-modern counterpart which offers a wider array of functionality, spans scope boundaries in being capable of working with projects written in multiple languages the likes of Java, C++ or Python, and brings significant performance improvements. (Gradle vs Maven: Performance Comparison).It's no coincidence that Google has chosen it as its official build system.

But what do all these have to do with Android Studio? Well Android Studio delegates everything about building an application to Gradle, although the same procedures could be very well performed on just the command line as well.



The instructors guiding us through the lessons are Mark Vieira, Core Engineer at Gradle and Jeremy Silver, Course Developer at Udacity. Their backgrounds promise the sharing of great insight, while the additional, unexpected, bonus was the bemusement that it involved. It turns out that Jeremy, as well as having a talent in tutoring, also has an equivalent talent in comedy and throughout his cleverly set up sketches manages to combine very technical and 'nerdy' topics with loads of fun!



In the very first lesson, Gradle Fundamentals, the duo introduces Gradle in relation to Java and Android. This includes installing it through its Wrapper, speeding it up through its Daemon, and performing Tasks, its core building blocks, from the CLI. Tasks are self-contained pieces of work which can be applied to any of the steps of the building phase of a project (a library or an application), such as compiling classes, resolving dependencies, producing reports, bundling resources and packaging applications.

A very simple task could be just printing 'Hello World' on the CLI:




but usually there are four main tasks that every type of project goes through, all of them revealed under:

gradle tasks --all :

    assemble (usually creates a jar)
    check (runs any tasks we've set up)
    build (depends on both assemble and check)
    clean (deletes all the build output)


The above code listing constitutes the 'buildscript', the container for all Tasks that supplies Gradle with custom configurations.Gradle scripts are themselves written in a DSL based on Groovy (for the low down on DSL's and how to construct your own languages head over to the How To Create Pragmatic, Lightweight Languages book review). The magic part is that this DSL can be further expanded through the so called 'plugins' which add new keywords, functionality and further tasks to the language. The code above uses the Android plugin, '', which adds several features specific to the building of Android applications. This plugin itself is based upon the Java plugin and there can be complex hierarchies where one plugin depends on another and so on.



Next are writing Gradle scripts in Groovy, building plain Java programms with the Java plugin and going through Gradle's dedicated use cases for the Android platform. These includes lessons on:

  • Build Types
  • Flavors, and Variants
  • Flavor Dimensions
  • Android vs Java Libraries
  • Multi-Project Builds
  • Application Signing
  • Multidex Support
  • Configuring Proguard
  • Android Testing

It should be noted that this module's material was by far the most manageable so far presented in the course, while the fun introduced by the sketches played its role in making the experience pleasant without compromising its great quality.

Despite that everything necessary for tackling the end project was supplied, the part on Instrumentation testing was however pretty light as such you had to cover any gaps left open by looking to external resources in setting the tests up. The final project itself, Build It Bigger, was both very interesting as well as challenging, even incorporating calling a Google Cloud Endpoint at the backend.



Last Updated ( Monday, 20 November 2017 )