什么是Android X

Whether you’re an experienced Android developer or are new to the platform, if you have written Android code recently, it’s highly likely that you have seen AndroidX all over the place. If you’re like me, most likely you don’t look into the details behind what this term means or what the difference is between it and other imports you make to your app, like the Support Library. But if you’re here, most likely you’re wondering what’s behind AndroidX. I hope to clarify some of your doubts about it.

无论您是经验丰富的Android开发人员还是该平台的新手,如果您最近编写了Android代码,那么很可能已经在各处看到了AndroidX。 如果您像我一样,很可能不会研究此术语的含义或它与您对应用程序进行的其他导入(例如支持库)之间的区别的细节。 但是,如果您在这里,最有可能想知道AndroidX的背后是什么。 我希望澄清您对此的一些疑问。

First things first. AndroidX stands for Android E X tension Libraries. This simple denotation makes it clearer for an experienced developer what’s behind the term. But if that’s not the case for you, don’t worry, I will go into detail soon.

首先是第一件事。 AndroidX代表Android EX张力库 。 这种简单的表达方式使经验丰富的开发人员可以更清楚地了解术语的含义。 但是,如果您不是这种情况,请不用担心,我会尽快详细介绍。

Before diving deeper, I would like to explore the first definition found in the Android documentation when searching for AndroidX:

在深入探讨之前,我想探索一下搜索AndroidX时在Android文档中找到的第一个定义:

“Artifacts within the androidx namespace comprise the Android Jetpack libraries. Like the Support Library, libraries in the androidx namespace ship separately from the Android platform and provide backward compatibility across Android releases." — AndroidX Overview

androidx 名称空间中的 工件 包含 Android Jetpack 库。 像支持库一样, androidx 名称空间中的 与Android平台分开提供,并在Android版本之间提供向后兼容性。” — AndroidX概述

I think that’s a bit hard to read and comprises a large amount of terminology that could be hard to wrap up. At the end of this piece, you’ll be able to go back to this definition and know what they were trying to say.

我认为这有点难以理解,并且包含大量可能难以总结的术语。 在本文的最后,您将可以回到该定义并了解他们想要说的话。

Android版本控制的背景 (Background on Android Versioning)

Android has a particular methodology for versioning the operating system. Currently (January 2020) there have been ten major versions of Android. The most recent version of Android is Android 10 (easy isn’t it?), released to the public on September 3, 2019. This is the version that should have been known as Android Q. All previous versions of Android were named alphabetically as a dessert: Android 1.5 Cupcake, Android 4.0 Ice Cream Sandwich, Android 9.0 Pie. But Android 10.0 was the exception as the corresponding dessert had to be named with Q, can you think of a name with Q? Well, Android branders apparently couldn’t or didn’t find any good enough, so this last version is just Android 10.

Android具有用于操作系统版本控制的特定方法。 当前(2020年1月)有十个主要版本的Android。 Android的最新版本是Android 10(不是吗?),于2019年9月3日向公众发布。这是应该被称为Android Q的版本。所有以前的Android版本都按字母顺序命名为甜点:Android 1.5纸杯蛋糕,Android 4.0冰淇淋三明治,Android 9.0 Pie。 但是Android 10.0是个例外,因为相应的甜点必须用Q命名,您能想到用Q命名吗? 好吧,Android品牌商显然找不到或没有找到足够好的产品,因此最后一个版本只是Android 10。

什么是支持库? (What Is the Support Library?)

In the second sentence of their definition, we can find the following text: “Like the support library, libraries in the AndroidX namespace… .” From this, we notice that they are assuming we all know what the support library is. Maybe you do, but just in case you don’t, let’s review it.

在其定义的第二句话中,我们可以找到以下文本:“像支持库一样,AndroidX名称空间中的库……。” 由此,我们注意到他们假设我们都知道支持库是什么。 也许您会这样做,但以防万一,让我们对其进行回顾。

Each Android version has different capabilities and new additions. Thinking back to the origins of Android in 2008, smartphones have changed a lot, which means they added and removed a large number of features. In the beginning, it was as simple as migrating from a physical to a digital keyboard, up to advanced features like the AI assistant aka “Ok Google.” Before the release of Android 9.0, we used the so-called Support Library to make our apps compatible across all the versions. These libraries managed features available or unavailable in different versions and helped developers create usable apps on all devices.

每个Android版本都有不同的功能和新增功能。 回顾2008年Android的起源,智能手机已经发生了很大变化,这意味着它们添加和删除了大量功能。 从一开始,它就像从物理键盘迁移到数字键盘一样简单,再到AI助手(又称“ Ok Google”)之类的高级功能。 在Android 9.0发行之前,我们使用了所谓的支持库来使我们的应用程序在所有版本中兼容。 这些库管理着不同版本中可用或不可用的功能,并帮助开发人员在所有设备上创建可用的应用程序。

为什么需要支持库? (Why Is the Support Library Needed?)

If you’re an Android user, you probably know that when you buy your device, it will get a couple of updates, but eventually, you won’t get new versions of Android. This is in part driven by hardware limitations, among other things. This is a larger topic for another piece.

如果您是Android用户,则可能知道购买设备会获得一些更新,但最终您将不会获得新版本的Android。 这在某种程度上是由硬件限制驱动的。 这是另一个更大的话题。

The important thing here is that different Android versions may have different names for libraries, methods, and functionality that are integrated within the operating system and won’t be delivered within your app APK. So to make sure the compiler understands your code and executes the same or similar functionality in all devices, support libraries take control and carry out this job for us. Support libraries are shipped with your app and are not tied to the Android version.

这里重要的是,不同的Android版本可能具有与操作系统中集成的库,方法和功能不同的名称,并且不会在您的应用APK中提供。 因此,要确保编译器理解您的代码并在所有设备中执行相同或相似的功能,请支持库来控制并完成我们的工作。 支持库随您的应用一起提供,并不与Android版本绑定。

If you want to dive deeper into the details of Support Library, have a look at Android documentation on this topic: https://developer.android.com/topic/libraries/support-library

如果您想深入了解支持库的详细信息,请查看有关此主题的Android文档: https : //developer.android.com/topic/libraries/support-library

Image for post
Photo by Jon Tyson on Unsplash
乔恩·泰森 ( Jon Tyson)Unsplash

Up to now, we have clarified all of the second sentence of the Android documentation: “Like the Support Library, libraries in theandroidx namespace ship separately from the Android platform and provide backward compatibility across Android releases." Yay us! Hopefully, these sounds more understandable now.

到目前为止,我们已经阐明了Android文档的所有第二句话:“像支持库一样, androidx名称空间中的库与Android平台分开提供,并提供了与Android版本之间的向后兼容性。”好的,听起来很androidx 。现在更容易理解。

We can go on and explore the first sentence: “Artifacts within the androidx namespace comprises the Android Jetpack libraries… ."

我们可以继续探索第一句话: androidx名称空间中的工件包括Android Jetpack库…。”

什么是Android Jetpack? (What Is Android Jetpack?)

The first thing mentioned there is Android Jetpack. This is a big topic by itself, but then again, let’s look at the Android documentation and their definition:

提到的第一件事是Android Jetpack。 就其本身而言,这是一个很大的话题,但是再来看一下Android文档及其定义:

“Jetpack encompasses a collection of Android libraries that incorporate best practices and provide backwards compatibility in your Android apps.” — Getting Started with Android Jetpack

“ Jetpack包含一系列Android库,这些库结合了最佳实践并在您的Android应用程序中提供向后兼容性。” Android Jetpack入门

Image for post
Photo by Mathew Schwartz on Unsplash
Mathew SchwartzUnsplash上的 照片

At least the definition here is easier to read, but did you think the same thing I did? The definition sounds exactly as if we were describing the Support Libraries. If we were in a multiple-choice exam and the options were a. Jetpack and b. Support Library, honestly, I wouldn’t know which to choose. (I hope there would be a c. All of the above).

至少这里的定义更容易阅读,但是您是否认为我也做同样的事情? 这个定义听起来很像我们在描述支持库。 如果我们参加多项选择考试,并且选项是a。 Jetpack和b。 老实说,支持库我不知道该选择哪个。 (我希望上面有c。)。

So here comes a new question: What is the difference between the Support Library and the new Jetpack? Basically, Jetpack is better organized and will be more consistent across devices. In developer terms, Jetpack is a refactor of all the support libraries. Why do I say all? Because if you look at the support libraries, they had different versions (v4, v7, v12, etc.) which made them really confusing and was becoming a big mess. With this change, you don’t have to worry about the version because Jetpack knows what code to use. In essence, they are the same, but from the outside, they are all condensed and become less work for the developer.

因此,出现了一个新问题:支持库和新的Jetpack有什么区别? 基本上,Jetpack的组织性更好,并且在各个设备之间将更加一致。 用开发人员的术语来说,Jetpack是所有支持库的重构。 我怎么都说 因为如果您看一下支持库,它们具有不同的版本(v4,v7,v12等),这使它们真的很混乱,并且变得一团糟。 进行此更改后,您不必担心版本,因为Jetpack知道要使用什么代码。 从本质上讲,它们是相同的,但是从外部看,它们都被压缩,从而减少了开发人员的工作量。

From the above and looking back to the definition, we can see that any library that starts with the word AndroidX is automatically part of Jetpack.

从以上内容开始,再回到定义,我们可以看到以AndroidX开头的任何库都自动成为Jetpack的一部分。

Hopefully, this piece answered the question that brought you here. In my opinion, it’s a bit confusing having two separate terms, Android Jetpack and AndroidX. Even if it’s not essential to understand all the logic behind the things we use day to day, knowledge of our subject will help us become better developers.

希望这篇文章回答了将您带到这里的问题。 我认为,使用两个单独的术语Android Jetpack和AndroidX有点令人困惑。 即使不一定要了解我们日常使用的事物背后的所有逻辑,了解我们的主题也会帮助我们成为更好的开发人员。

Until next time!

直到下一次!

翻译自: https://medium.com/better-programming/what-is-android-x-96fc5593b421

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值