Skip to content

Introduction to Android Jetpack and its Components

Google I/O 2019 unveiled a lot about Jetpack, also known as Android X including the new Android X Preferences, SavedState with View Models, and even the new Camera X library. For some of us (including me), this might have been the first time hearing about Jetpack and it’s definitely becoming pretty big, so let’s look into it.

According to the Android Developer Site, Jetpack is a suite of libraries, tools, and guidance to help developers write high-quality apps easier. Applications go from simplifying complex code, removing boilerplate code, and just enforcing best practices to keep code maintainable.

 

Jetpack is pushing the trend of accelerating development and making it easier to build high quality robust apps to keep developers productive and our users happy.

This is the trend the Android community has been pushing forward and I love it. Making Android development, well, easy. For beginners, it helps them get into the ecosystem much more smoothly. For adepts, it helps us build apps at light speeds.

Jetpack Components

Jetpack includes components split into these 4 categories: Architecture, Foundation, UI, and Behavior. Taking the words straight from the site:

Foundation – Cross-cutting functionality like backwards compatibility, testing and Kotlin language support. This includes Benchmark, Security, and Wear OS components among others.

Architecture – Help you design robust, testable and maintainable apps. This includes Data Binding, Lifecycle, and View Model components.

UI – Widgets and helpers to make your app not only easy, but delightful to use. This includes Emoji, Fragment, and Layout components.

Behavior – Help your app integrate with standard Android services like notifications, permissions, sharing and the Assistant. This includes Notifications, Preferences, and Media components.

We’ll look into some of the more significant individual components later on.

Adding Jetpack to your App

Jetpack is available as part of the Google Maven Repository. If you haven’t added that already, go to your project-level build.gradle file and add the Google repository down there.

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Then you can add the individual components in your app-level build.gradle file.

// For Kotlin use navigation-fragment-ktx
implementation 'androidx.navigation:navigation-fragment:$nav_version'

Exploring Components

At first glance, Jetpack is HUGE, then you start looking into it and realize you’ve been interacting with many of its components all along. I want to explore some of its components in each category just briefly just so we can get a feel for the Jetpack experience. The list below includes some but not all of Jetpack’s components.

Foundation Components

Android KTX – Provides even more streamlining to the already concise Kotlin for core language functions as well as other Jetpack libraries.

Benchmark – Benchmark your code from within Android Studio, letting the library warmup, measure code performance, and output it to the Studio console.

Multidex – Allow your app to exceed 64k methods

Security – Implement best practices that allow for great encryption and good performance

 

Architecture Components

Data Binding – android:text=”@{viewmodel.userName}”… enough said

Lifecycles – Build components that adjust their behavior based on the lifecycle state of the activity or fragment

Room – Super robust way to access your SQLite database

View Model – Store UI data in an object separate from the Activity/Fragment so it survives screen configuration changes like screen rotation

Work Manager – Schedule deferrable, asynchronous tasks that are expected to run even if the app exits or device restarts

 

UI Components

Compose – The new library announced in I/O ’19 that makes it easier to create new components without having to rely on an XML layout

Slices – UI templates that can display rich, dynamic, and interactive content from your app from within the Google Search app and later in other places like the Google Assistant

Palette – Extract the primary colors of an image in your app

View Pager 2 – A better View Pager based on Recycler View with RTL support and vertical paging

Fragments, Layouts, Animations – Your everyday building blocks of Android UI that just so happen to be Jetpack components

 

Behavior Components

CameraX – A new camera library that simplifies camera development even further and integrates with newer camera technologies like Pixel 3’s Night mode

Preferences – A new updated preference library that should be used over the old standard Android preferences

Sharing, Notifications, Download Manager – More everyday things that just so happen to be Jetpack components.

Tags: