This article was first published on the wechat public account “Houchangcun Mannong”
preface
Android has developed for 11 years, which can be said to be a relatively mature technology. At the beginning, there were few frameworks and no specifications. All the code had to be written by ourselves, such as network requests, database requests, data parsing and so on. Later, some frameworks emerged to help developers develop quickly, such as XUtils, Volley, OKHttp, EventBus, etc. With more and more frameworks, one application can have multiple technology selection, which directly leads to more and more non-standard application development, resulting in uneven application quality, which is obviously not what Google wants to see. Google has since released an official example of MVP and MVVM, which is mediocre and covers only architectural issues, but Android Jetpack, which was unveiled at Google I/O 2018, is expected to address these issues.
1. The Android Jetpack profile
Jetpack is not a framework or component; it is a collection of libraries, tools, and guidelines that make it easier for developers to write quality applications. These components help developers follow best practices, get rid of boilerplate code, and simplify complex tasks so they can focus on the code they need. Many of the components in Android Jetpack are not new, but have been around for a long time, such as the Android Architecture Component (AAC) introduced at Goole I/O 2017, It includes LifeCycle, LiveData, ViewModel, Room. At Goole I/O 2018, Android Support Library was replaced with AndroidX and Android Architecture Component was released with Android Jetpack, AndroidX is also part of Android Jetpack.
Jetpack has three key features: 1. Accelerated development Components can be used individually or in collaboration, which increases efficiency when using kotlin language features.
2. Eliminate boilerplate code Android Jetpack manages tedious activities such as background tasks, navigation, and lifecycle management.
The Android Jetpack component is built around modern design practices and is backward compatible to reduce crashes and memory leaks.
2. The Android Jetpack classification
Below is Jetpack’s taxonomy.
2.1 Architecture
Architecture refers to the architectural components that help developers design robust, testable, and maintainable applications. Architectural components are arguably the most important component for application development, and this series focuses on architectural components.
DataBinding: Declaratively binds observable data to interface elements, usually in conjunction with ViewModel. Lifecycle: Manage the Lifecycle of activities and fragments to help developers generate lightweight code that is easier to maintain. LiveData: Notifies the view when the underlying database changes. It is an observable data holder, and unlike a regular Observable, LiveData is lifecycle aware. Navigation: Handles in-app Navigation. Paging: Enables developers to load and display small pieces of data at a time. Loading partial data on demand reduces network bandwidth and system resource usage. Room: Friendly and smooth access to SQLite database. It provides an abstraction layer on top of SQLite, allowing for more powerful database access. ViewModel: Managing data related to the interface in a lifecycle manner, often in conjunction with DataBinding, provides powerful support for developers implementing the MVVM architecture. WorkManager: A job that manages the Android background and can run deferred asynchronous tasks even after the application exits or the device is restarted.
The official recommended Android application architecture is shown below.
These architectural components can be used together or separately, and it is recommended to follow the official recommendations as much as possible.
2.2 Foundationy (Basic Components)
The base component provides horizontal functionality, such as backward compatibility, testing, security, Kotlin language support, and includes multiple components developed for multiple platforms.
Android KTX: Optimized Jetpack and Android platform apis for Kotlin. Help developers use Kotlin for Android development in a simpler, more enjoyable, and more idiomatic way. AppCompat: Helps with compatibility with older versions of Android. Auto: The component that develops the Android Auto application that provides a standardized interface and user interaction for all vehicles. Check: quickly check Kotlin or java-based code from AndroidStudio. Multi-dex processing: Supports applications with multiple Dex files. Security: Secure reading and writing of encrypted files and sharing preferences. Testing: 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 for developing Wear applications.
2.3 Behavior (Behavior Component)
Behavior components help developers integrate their apps with standard Android services such as notifications, permissions, and sharing.
CameraX: Helps developers simplify the development of camera applications. It provides a consistent and easy-to-use interface that works with most Androids. The device is backward compatible to Android 5.0 (API 21). DownloadManager: A system service that handles long-running HTTP downloads. Media and Playback: Backward-compatible APIS for media playback and routing, including Google Cast. Notifications: Provides backwards-compatible notifications API, supports Wear and Auto. Permissions: Compatibility API for checking and requesting application permissions. Settings: Create interactive Settings. It is recommended to use the AndroidX Preference Library to integrate user-configurable Settings into the app. Sharing operations: User-friendly sharing operations can be implemented more easily. Slicing: Slicing is a UI template that creates flexible interface elements that display application data outside the application.
2.4 UI (Interface Components)
Animation and Transition: This framework contains built-in animations for common effects and allows developers to create custom animations and lifecycle callbacks. Emoji Compatibility: Users can get the latest Emoji even if they haven’t updated Android. Fragment: Basic unit of a componentized interface. Layout: Declare UI elements in XML or instantiate UI elements in code. Palette: Extract useful information from the palette.
3. Include Jetpack-related components in your app
Add the Google () library to the project build.gradle, as shown below.
allprojects {
repositories {
google()
jcenter()
}
}
Copy the code
If you want to introduce Room, you can write this in the build.gradle module:
implementation "Android. Arch. Persistence. Room: the runtime: 1.1.1"
annotationProcessor "Android. Arch. Persistence. Room: the compiler: 1.1.1"
androidTestImplementation "Android. Arch. Persistence. Room: testing: 1.1.1"
Copy the code
conclusion
This article is intended to give you an idea of what Android Jetpack is, what it includes, and how to reference it. Starting with the next article, you will learn about the architectural components of Android Jetpack.
Here not only share big front end, Android, Java and other technologies, but also programmer growth class articles.