This article is first published in the wechat public account “Android development journey”, welcome to follow, get more technical dry goods

Wan-android Jetpack VersionAndroid Jetpack architecture for componentized application developmentWelcome to star

Project address of Flutter wan-AndroidFlutter Wan – AndroidWelcome to star

Introduction to the

Jetpack is a collection of libraries, tools, and tutorials that make it easier for developers to write and build great Android applications.

Some of the components in Jetpack aren’t new, LifeCycle, LiveData, ViewModel, Room and other components were introduced at Google I/O 2017 along with the Android Architecture Component (AAC), but were poorly promoted. A year later, Google released Jetpack on top of AAC, along with other tools to address Android technology selection and development irregularities.

Jetpack has the following features:

  • Accelerated development: Components can be adopted individually (although they are built to work together) while leveraging Kotlin language capabilities to help you be more productive.

  • Eliminate boilerplate code: Jetpack manages cumbersome activities such as background tasks, navigation, and lifecycle management.

  • Build high quality powerful applications: Jetpack components are built around modern design practices with backward compatibility to reduce crashes and memory leaks.

Jetpack classification

Android Jetpack components fall into four broad categories: Foundation, Architecture, Behavior, and UI.

Foundation:

The base component provides horizontal functionality such as backward compatibility, testing, and support for the Kotlin language. It contains the following component libraries:

  • Android KTX: Android KTX is a set of Kotlin extensions that optimize Jetpack and the Android platform apis for Kotlin. Use Kotlin for Android development in a simpler, more enjoyable, and more idiomatic way.

  • AppCompat: A series of apis starting with AppCompat are provided for compatibility with lower versions of Android development.

  • Cars(Auto) : Components that help develop Android Auto apps without worrying about vehicle-specific hardware differences such as screen resolution, software interface, knobs, and touch-sensitive controls.

  • Benchmark: Quickly Benchmark Kotlin – or Java-based code from Android Studio. Measure code performance and output benchmark analysis results to the Android Studio console.

  • Multidex: enable multiple Dex files for applications with more than 64K methods.

  • Security: Read and write encrypted files and share preferences according to Security best practices.

  • Test: An Android testing framework for unit and runtime interface testing.

  • TV: Build apps that allow users to experience immersive content on the big screen.

  • Wear OS: Components that help develop Wear applications.

Architecture:

Architectural components help developers design robust, testable, and maintainable applications. It contains the following component libraries:

  • Data Binding: A Data Binding library is a support library that allows you to declaratively bind interface components in a layout to Data sources in an application.

  • Lifecycles: Easy to manage Activity and Fragment Lifecycles, helping developers write lighter, easier to maintain code.

  • LiveData: is an observable data holder class. Unlike regular Observables, LiveData is lifecycle aware.

  • Navigation: Handles everything needed for in-app Navigation.

  • Paging: Helps developers load and display small pieces of data at once. Loading partial data on demand reduces network bandwidth and system resource usage.

  • Room: The Room persistence library provides an abstraction layer on TOP of SQLite to help developers access SQLite databases in a friendly and smooth way.

  • ViewModel: Stores and manages UI-related data in a life-cycle-aware manner.

  • WorkManager: It is easy to schedule deferred asynchronous tasks that are expected to run even if the application exits or the device is restarted.

Google’s recommended application architectures:

Behavior:

Behavior components help developers integrate their apps with standard Android services such as notifications, permissions, sharing, and Google Assistant. It contains the following component libraries:

  • CameraX: Helps developers simplify camera application development. It provides a consistent and easy-to-use API interface that works on most Android devices and is backward compatible up to Android 5.0 (API level 21).

  • DownloadManager: Handles long-running HTTP downloads and retries them in the event of a failure or after connection changes and system restarts.

  • Media & Playback: Backward-compatible API for Media playback and routing, including Google Cast.

  • Notifications: Provides backwards-compatible notification apis with support for Wear and Auto.

  • Permissions: Compatibility API for checking and requesting application Permissions.

  • Preferences: Provides the ability for users to change the functionality and behavior of the application.

  • Sharing: Provides Sharing operations suitable for the application action bar.

  • Slices: Create flexible interface elements that display application data outside the application.

UI(Interface component) :

Interface components can provide various views and auxiliary programs, making the application not only easy to use, but also a pleasant experience. It contains the following component libraries:

  • Animation & Transitions: Provides a variety of built-in animations, as well as custom Animation effects.

  • Emoji: Allows users to use emojis without updating the system.

  • Fragment: Basic unit of a componentized interface.

  • Layout: An INTERFACE Layout written in XML or composed using Compose.

  • Palette: To extract useful information from the Palette.

Use the Jetpack

Jetpack components are currently included in AndroidX, so there is no need for additional packages if the project is migrated to AndroidX. If it is not compatible with AndroidX, you need to configure it in Gradle:

Open your project build.gradle and add the Google () code base as follows:

allprojects {
    repositories {
        google()
        jcenter()
    }
}
Copy the code

For example if Lifecycle is only used Lifecycle open your app build.gradle and add dependencies:

implementation "android.arch.lifecycle:runtime:$lifecycle_version"
annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version"
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
Copy the code

conclusion

This article introduces the origin and classification of Jetpack components, and explains the meaning of each component in detail. To give you a good idea of Jetpack, each component can be used individually or in combination. Later we will focus on the use of related components of Architecture. Scan the qr code below to follow the public account, timely access to the article push.

Scan the qr code below to follow the public account for more technical dry goods.

Recommended reading

Android Jetpack Architecture Component – Lifecycle Into the pit Guide

Jetpack architecture components – LiveData and ViewModel cratering details

Android Jetpack architecture component – Room in detail