What Is Android Jetpack? And What’s New In Now-A-Days

xpertlab-type-script
TypeScript 3.5 Fixes ‘unbearably slow’ Type-Checking Bug
24th May 2019
xpertlab-cloud-comparisions
Clouds Comparisons – Which One Is The Best
29th May 2019

Android Jetpack is a set of components, tools and guidance to make great Android apps. The Android Jetpack components bring together the existing Support Library and Architecture Components and arranges them into four categories:

xpertlab-jetpack

Android Jetpack components are provided as “unbundled” libraries that are not part of the underlying Android platform. Thus This means that you can adopt each component at your own speed, at your own time. When new Android Jetpack functionality is available, you can add it to your app, deploy your app to the Play Store and give users the new features all in a single day (if you’re quick)! The unbundled Android Jetpack libraries have all been moved into the new androidx.* namespace.

In addition, your app can run on various versions of the platform because Android Jetpack components are built to provide their functionality independent of any specific version, providing backwards compatibility.

Further, Android Jetpack is built around modern design practices like separation of concerns and testability as well as productivity features like Kotlin integration. This makes it far easier for you to build robust, high quality apps with less code. While the components of Android Jetpack are built to work together, e.g. lifecycle awareness and live data, you don’t have to use all of them — you can integrate the parts of Android Jetpack that solve your problems while keeping the parts of your app that are already working great.

Android Jetpack is a collection of Android software components which helps us in building great Android apps.

Software Components

  • Following the best practices and writing the boilerplate code.
  • Making complex things very simple.

Earlier there were many challenges which are as follows:

  • Managing activity lifecycles.
  • Surviving configuration changes.
  • Preventing memory leaks.

And TAll these major problems have been solved by the Android Jetpack’s software components.

So, the solution for all the problems is Andriod Jetpack.

Another most important thing about the Jetpack is that it gets updated more frequently than the Android platform so that we always get the latest version.

Jetpack comprises the androidx.* package libraries, unbundled from the platform APIs. This means that it offers backward compatibility.

Android Jetpack Components

Android Jetpack components are a collection of libraries that are individually adoptable and built to work together while taking advantage of Kotlin language features that make us more productive.

These software components have been arranged in 4 categories which are as follows:

  • Foundation Components
  • Architecture Components
  • Behavior Components
  • UI Components

Foundation Components

The foundation components provide the following:

  • Backward compatibility
  • Testing
  • Kotlin language support.

All the foundation components are as follows:

  • App Compat:
    • Degrade gracefully on older versions of Android with material design user interface implementation support.
  • Android KTX:
    • Set of Kotlin extensions to write more concise, idiomatic Kotlin code.
  • Multidex:
    • Provide support for multiple dex files for apps.
  • Test:
    • A testing framework for unit and runtime UI tests in Android.

Architecture Components

The architecture components help us in building:

  • Robust Apps
  • Testable Apps
  • Maintainable Apps

All the architecture components are as follows:

  • Data Binding:
    • Declaratively bind UI elements to in our layout to data sources of our app.
  • Lifecycles:
    • Manages activity and fragment lifecycles of our app.
  • LiveData:
    • Notify views of any database changes.
  • Navigation:
    • Handle everything needed for in-app navigation.
  • Paging:
    • Gradually load information on demand from your data source.
  • Room:
    • Fluent SQLite database access.
  • ViewModel:
    • Manage UI-related data in a lifecycle-conscious way.
  • WorkManager:
    • Manage every background jobs in Android with the circumstances we choose.

Behavior Components

The behavior components help in the integration with standard Android services like

  • Notifications
  • Permissions
  • Sharing
  • Assistant

All the behavior components are as follows:

  • Download Manager:
    • Schedule and manage large downloads in background with auto retry support.
  • Media & playback:
    • Backwards compatible APIs for media playback and routing (including Google Cast).
  • Notifications:
    • Provides a backwards-compatible notification API with Wear and Auto support.
  • Permissions:
    • Compatibility APIs for checking and requesting permissions in app.
  • Preferences:
    • Create interactive settings screens for users to configure.
  • Sharing:
    • Provides a share action suitable for an app’s action bar.
  • Slices:
    • Create flexible UI elements that can display app data outside the app and can be extended all the way back to Android 4.4.

UI Components

The UI components provide widgets and helpers to make your app not only easy, but delightful to use.

All the UI components are as follows:

  • Animation and transitions:
    • Move widgets and transition between screens.
  • Auto:
    • Components to develop Android Auto apps.
  • Emoji:
    • Enable updated emoji font on older platforms.
  • Fragment:
    • A basic unit of composable UI.
  • Layout:
    • Layout widgets with different algorithms.
  • Palette:
    • Pull useful information from color palettes.
  • TV:
    • Components to develop Android TV apps.
  • Wear:
    • Components to develop Wear apps.

What’ New Current Android JetPack ?

At its I/O 2019 developer conference, Google announced 10 new libraries for Android Jetpack, its set of components, tools, and guidance designed to accelerate app development. The company also unveiled Jetpack Compose, a new unbundled Kotlin toolkit.

Think of Android Jetpack as the successor to Support Library, a set of components that makes it easier to leverage new Android features while maintaining backwards compatibility. When Google launched Jetpack last year at I/O 2018, Android product manager Stephanie Cuthbertson described it as “the next generation of Android APIs designed to accelerate app development.”

Last year, Google said Support Library was used by 99% of all the apps in the Play Store. Today, Cuthbertson revealed that 80% of the top 1,000 apps in the Play store are using Jetpack.

In March, Google announced the stable releases of Jetpack WorkManager (background processing) and Jetpack Navigation (in-app navigation). The 10 new libraries the company is announcing today are deemed ready for production, even though they’re not quite finished.

Seven Libraries Are In Alpha:

CameraX:

Create camera-driven experiences in your application without worrying about the underlying device behavior or backwards compatibility. This API is backwards compatible to Android 5.0 (API 21) or higher, ensuring that the same code works on most devices in the market. It leverages the capabilities of camera2, but uses a simpler, use case-based approach that is lifecycle-aware. This eliminates significant boilerplate code when compared with camera2. It further enables you to access the same functionality as the native camera app on supported devices. Plus, optional extensions enable features like Portrait, Night, HDR, and Beauty.

LiveData and Lifecycles with coroutines:

Lifecycle & LiveData KTX support common one-shot asynchronous operations so you can use Kotlin coroutines that are lifecycle-aware. Offering coroutine scopes tied to lifecycles, coroutine dispatchers that are lifecycle-aware, and support for simple asynchronous chains with the new LiveData builder let you use Kotlin coroutines safely.

Benchmark:

A quick way to benchmark your app code, whether it is written in Kotlin, Java, or native code. Ensure you do not introduce any latency into your code right within your development environment in Android Studio. Easily measure database queries, view inflation, or a RecyclerView scroll. The library takes care of what is needed to provide reliable and consistent results, like handling warm-up periods, removing outliers, and locking CPU clocks.

Security:

Maximize security of an application’s data at-rest by letting this library implement security best practices for you. It provides strong security that balances encryption with performance for consumer apps like banking and chat. It also provides a maximum level of security for apps that require a hardware-backed keystore with user presence and simplifies many operations, including key generation and validation.

ViewModel with SavedState:

It provides an easy way to save your UI data in the event of a configuration change but doesn’t save your app state in the event of process death. ViewModel with SavedState lets you eliminate boilerplate code. Gain the benefits of using both ViewModel and SavedState with simple APIs to save and retrieve data right from your ViewModel.

ViewPager2:

ViewPager is now based on RecyclerView and supports vertical scrolling and RTL (Right-to-Left) layouts. It also provides a much easier way to listen for page data changes with registerOnPageChangeCallback.

Three Libraries Are In Beta:

  • Biometrics Prompt:
    • Provide a consistent and safe way for your users to enter their credentials with a biometric login. This library provides a simple system prompt, giving the user a trustworthy experience.
  • Enterprise:
    • Your managed enterprise apps can send feedback back to Enterprise Mobility Management providers in the form of keyed app states. Also, you can take advantage of backwards compatibility with managed configurations.
  • Android for Cars:
    • Provide your users with a driver-optimized version of your app that will be automatically installed on the vehicle’s infotainment system in vehicles equipped with Android Automotive. This OS also lets your apps work with the Android Auto app.

Google says these APIs were shaped using feedback from Android developers. The company specifically noted its early access developer programs, user studies, and communities on Reddit, Stack Overflow, and Slack.

Jetpack Compose

Google today also open-sourced an early preview of Jetpack Compose. The new unbundled toolkit is meant to simplify UI development by combining a reactive programming model with Kotlin.

Don’t try Jetpack Compose on any production projects — the toolkit is nowhere near ready. “It’s not even alpha,” Chet Haase, chief advocate for Android, told VentureBeat. But Google is going to develop Jetpack Compose in the open anyway, starting today, in hopes of getting developers to share their thoughts.

Android group product manager Karen Ng led the Jetpack Compose effort. She told VentureBeat her team wanted to solve major developer pain points, and UI is an area that Jetpack hasn’t tackled yet.

“Jetpack Compose is built with all the benefits of Kotlin,” Ng explained. “So it’s entirely interoperable with Java. It’s fully declarative, for defining UI components, including drawing and custom layouts, which is not super common.

So it means that you can just describe your UI as a set of functions. And then the framework itself handles all the UI optimizations under the hood, and also automatically updates the view hierarchy, rather than having the app developer maintain that themselves. It’s compatible with all existing views. So you can mix and match our current views with what we call composable views. And then it’s designed with Material and animations right from the start.”

Google justifies Jetpack Compose by saying that developers like reactive APIs and love Kotlin. The company is thus investing in the reactive approach to declarative programming and creating a way to build UIs with Kotlin.

Jetpack Compose Comes With Few Core Principles

  • Build with the benefits that Kotlin brings — concise, safe, and fully interoperable with the Java programming language. Designed to drastically reduce the amount of boilerplate code you have to write, so you can focus on your app code, and help avoid entire classes of errors.
  • Fully declarative for defining UI components, including drawing and creating custom layouts. Simply describe your UI as a set of composable functions, and the framework handles UI optimizations and updates to the view hierarchy under the hood.
  • Provide reusable building blocks that let you build custom widgets easier, and without starting from scratch.
  • Compatible with existing views so you can mix and match and adopt at your own pace with direct access to all of the Android and Jetpack APIs.
  • Material Design out of the box and animations from the start, so it’s easy to create beautiful apps that are full of motion.
  • Accelerate development with tools like Live Preview and apply changes.

A Jetpack Compose application is made up of composable functions that transform application data into a UI hierarchy. To create a composable function, just add the @Composable annotation to the function name. Jetpack Compose uses a custom Kotlin compiler plugin under the hood — when the underlying data changes, the composable functions can be re-invoked to generate an updated UI hierarchy.