现在在Android 14中

Welcome to Now in Android, your ongoing guide to what’s new and notable in the world of Android development.

欢迎使用Android Now,这是您持续不断的有关Android开发领域新事物和着名指南。

Hey everyone: I hope everyone is staying safe and healthy. If you’re hunkered down sheltering and working at home like I am these days, maybe you want some developer bits to dive into. Here are some recent pieces from the Android team that are worth checking out.

大家好:我希望大家都保持安全和健康。 如果您像我现在这样渴望住所和在家里工作,也许您想让一些开发人员参与其中。 这是来自Android团队的最新作品,值得一试。

NiA14视频和播客形式 (NiA14 in Video and Podcast Form)

This Now in Android is also offered in video and podcast form. It’s the same content, but with less reading required. The article version (keep reading!) is still the place to come for links to all of the content that’s covered.

Android中的 This Now还以视频和播客形式提供。 内容相同,但所需的阅读量更少。 仍然可以使用文章版本(请继续阅读!)链接到所涵盖的所有内容。

视频 (Video)

播客 (Podcast)

Click on the link below, or just subscribe to the podcast in your favorite client app.

单击下面的链接,或只订阅您喜欢的客户端应用程序中的播客。

Android 11:开发人员预览版2 (Android 11: Developer Preview 2)

Image for post
Dial it up to Android 11
拨号到Android 11

I talked about the first preview for Android 11 in episode #13. And now, the next release has already dropped. Dave Burke posted an overview of the release on the Android Developers Blog. Check out the preview for updates to some of the features that were already in the release, as well as some new shiny features that are just now available, including my personal favorite feature: IME animation control.

我在第13集中谈到了Android 11的首次预览。 现在,下一个版本已经发布。 Dave Burke在Android开发者博客上发布了该版本概述 。 查看预览 ,以了解对该版本中已有功能的更新,以及一些新的闪亮功能,这些功能包括我个人最喜欢的功能:IME动画控件。

同步的IME动画 (Synchronized IME Animations)

For a platform developer, all new features are like our children: we have no favorites. But really, IME animation control is my favorite-favorite feature. You’ve been asking us for this feature (and we’ve been wanting it ourselves!) for several years, and now it’s here.

对于平台开发人员而言, 所有新功能都像我们的孩子一样:我们没有收藏夹。 但实际上,IME动画控件是我最喜欢的功能。 几年来您一直在要求我们提供此功能(我们一直都在想要它!),现在就在这里。

The idea is that the IME (keyboard) pops up on its own when keyboard entry is needed. This is the functionality the user needs, but it doesn’t provide the experience that users or developers want, because the appearance creates a visual discontinuity by simply popping into place, causing the apps to snap into their adjusted layout given the change in available screen real estate. The keyboard actually does animate in… but the app snaps instantly to the post-animation size, causing this visual hiccup.

这个想法是当需要输入键盘时,IME(键盘)会自动弹出。 这是用户所需的功能,但不能提供用户或开发人员想要的体验,因为外观通过简单地弹出就位会产生视觉上的不连续性,从而在可用屏幕发生变化的情况下使应用程序按入调整后的布局房地产。 键盘实际上可以进行动画处理,但是应用程序会立即捕捉到动画后的大小,从而引起视觉上的困扰。

What developers want, and what the new APIs provide, is the ability to both listen to information about the IME position as it animates in (so that apps can synchronize their own animations to suit) and to control the animation of the IME. Between the listener and the animation control, applications now have enough capability to create experiences that blend the change in the application UI with the animation of the IME itself, providing a much better experience.

开发人员想要的以及新的API提供的功能是既可以侦听有关IME动画的IME位置的信息 (以便应用程序可以同步其自己的动画以适应) 控制IME的动画 。 在侦听器和动画控件之间,应用程序现在具有足够的能力来创建将应用程序UI中的更改与IME自身的动画混合在一起的体验,从而提供更好的体验。

By the way, this feature has actually been in the works for a while. In fact, it nearly hit Android 10… but wasn’t quite ready, so we had to finish it up for Android 11 instead.

顺便说一句,该功能实际上已经使用了一段时间。 实际上,它几乎达到了Android 10的水平……但是还没有准备好,因此我们不得不为Android 11完成它。

NDK图像解码器 (NDK Image Decoder)

Another new API added in Android 11 is an image decoder for the NDK, especially for you native-code developers out there. If you’re currently jumping up through JNI to decode your images through the platform APIs or worse (from an app-size standpoint at least), bundling other libraries to handle image decoding, then we have a deal for you…

Android 11中添加的另一个新API是NDK的图像解码器,特别适合您在那里的本机代码开发人员。 如果您当前正在通过JNI跳过平台API或更糟糕的图像(至少从应用程序大小的角度来看),将其他库捆绑在一起以处理图像解码,那么我们为您提供了一笔交易...

You can now use the new NDK ImageDecoder API to handle images in common formats (such as JPEG, PNG, GIF, WebP, and HEIF). Check out the NDK guide for more information. Also check out the ImageDecoder sample, especially Texture.cpp, to see how it works.

现在,您可以使用新的NDK ImageDecoder API处理常见格式的图像(例如JPEG,PNG,GIF,WebP和HEIF)。 查阅NDK指南以获取更多信息。 还检查了ImageDecoder样品 ,尤其是Texture.cpp ,看看它是如何工作的。

Android 11中的可空性 (Nullability in Android 11)

We also added new nullability annotations to the SDK APIs in Android 11.

我们还向Android 11中的SDK API添加了新的可空性注释。

David Winer posted this article on the Android Developers Blog:

David Winer在Android开发者博客上发布了这篇文章:

which talks about nullability in Kotlin and how that works with APIs written in the Java programming language (which supports nullability through annotations, as opposed to Kotlin’s language support for nullability).

讨论了Kotlin中的可空性以及如何与用Java编程语言编写的API一起工作(通过注释支持可空性,而不是Kotlin对可空性的语言支持)。

Specifically, Android 11 introduced new annotations across the API that may introduce new warnings and errors when building (it’s a good thing! Catch those problems at build time instead of at runtime!). Some APIs that used to have @RecentlyNullable or @RecentlyNonNull (which may throw warnings from the Kotlin compiler when used incorrectly) were upgraded to @Nullable and @NonNull (which generate build-time errors instead). We also added new @RecentlyNullable and @RecentlyNonNull annotations to APIs that did not yet have any annotations. So build your apps and look for new warnings and errors to fix.

具体来说,Android 11在整个API中引入了新的批注,在构建时可能会引入新的警告和错误(这是一件好事!在构建时而不是在运行时捕获这些问题!)。 某些曾经具有@RecentlyNullable或@RecentlyNonNull(如果使用不正确,可能会从Kotlin编译器发出警告)的API已升级为@Nullable和@NonNull(它们会生成生成时错误)。 我们还向尚未具有任何批注的API添加了新的@RecentlyNullable和@RecentlyNonNull批注。 因此,请构建您的应用并寻找新的警告和错误来修复。

但是,等等,还有更多! (But Wait, There’s More!)

Other things we’ve added to Android 11 since the last preview release include:

自上一个预览版以来,我们添加到Android 11的其他内容包括:

  • There is now a hinge angle sensor for foldable devices.

    现在有一种用于可折叠设备的铰链角度传感器

  • NNAPI added a “hard-swish op,” which enables faster and more accurate training. I’m not sure of the details here, but I like the name. Bonus points for the very academic article that explains the theory behind swish activation functions if you want to know more.

    NNAPI添加了“强制操作”,可以更快,更准确地进行培训。 我不确定这里的细节,但我喜欢这个名字。 如果您想了解更多的知识, 那篇很有学术性的文章将为您解释奖励激活功能背后的理论,这是加分项。

  • Starting in Android 11, apps that want to use the microphone or camera from a foreground service need to add the foregroundServiceType attribute to their manifest, just like the location changes in Android 10. Note that we also talked about this change with the engineering team in episode 133 of the ADB podcast, Power Play.

    在Android的11起,即要使用的麦克风或摄像头,从前台服务需要的应用程序的添加foregroundServiceType属性到他们的表现,就像在Android的10注位置的变化,我们也谈到了与工程团队在这一变革亚行播客133集(Power Play)

  • Apps can now request variable refresh rates on supporting devices.

    应用现在可以在支持的设备上请求可变的刷新率

  • The emulator now supports both front and back cameras.

    该仿真器现在支持前置和后置摄像头。

The whole reason that we do preview releases is to give you a chance to try your app out on these early releases to make sure that things are working for you. This extra time gives you a chance to either fix problems if you see any, or to report issues for us to fix before we finish up the release and ship the final version. To help you, we’ve added a new settings screen in developer options where you can toggle various behavior changes to see whether they have any impact on your situation. So now would be an excellent time to try out Android 11 and see how it’s working for you.

我们进行预览发行的全部原因是让您有机会在这些早期发行版上试用您的应用,以确保一切正常。 这段额外的时间使您有机会解决问题(如果发现任何问题),或者在我们完成发行并发布最终版本之前向我们报告问题。 为了帮助您,我们在开发人员选项中添加了新的设置屏幕 ,您可以在其中切换各种行为更改,以查看它们是否对您的情况有影响。 因此,现在是试用Android 11并查看它如何为您工作的绝佳时机。

Read Dave Burke’s post for more information, or go get all of the details and the bits on the Android 11 Preview site. And please give us feedback if you have any, or even fill out a survey to let us know your thoughts on the updates and changes.

阅读Dave Burke的文章以了解更多信息,或者在Android 11 Preview网站上获取所有详细信息和内容。 如果有的话,请给我们反馈 ,甚至填写调查表 ,让我们知道您对更新和更改的想法。

AndroidX版本 (AndroidX Releases)

There have been various notable AndroidX releases lately.

最近出现了许多著名的AndroidX版本。

Beta:CameraX (Beta: CameraX)

Image for post

The CameraX library, created to make it easier to develop camera functionality (even across a diverse device ecosystem) has now entered Beta. This means that the API will remain steady as the team fixes issues before the library reaches stable.

为简化相机功能(即使在不同的设备生态系统中)开发相机功能而创建的CameraX库现已进入Beta版。 这意味着当团队在库达到稳定之前解决问题时,API将保持稳定。

In case you haven’t looked at it since it was first released in alpha form, some of the improvements of the Beta release include:

万一自从以Alpha形式首次发布以来您还没有看过它,Beta版本的一些改进包括:

Another release worth noting is the still-in-alpha (alpha08 as of this writing) Camera View module, which provides helpful components related to Views for camera applications.

另一个值得注意的发行版是仍然处于Alpha状态(在撰写本文时为alpha08)的Camera View模块,该模块提供了与适用于相机应用程序的View相关的有用组件。

You can read more about this release in Oscar Wahltinez’s article, check out the CameraX overview, or you can see more about the various modules of CameraX on the AndroidX camera release page.

您可以在Oscar Wahltinez文章中阅读有关此版本的更多信息,查看CameraX概述 ,或者在AndroidX相机发布页面上查看有关CameraX各个模块的更多信息。

稳定 (Stable)

A few libraries went stable with mostly bug fixes and minor features, including:

一些库在大部分错误修复和次要功能中保持稳定 ,包括:

  • Fragment 1.2.3

    片段1.2.3

  • Paging 2.1.2, which fixes an issue with 2.1.1 where some partially-implemented APIs were inadvertently exposed a bit too early, causing potential build or runtime problems (read: stop using 2.1.1, upgrade to 2.1.2 now)

    Paging 2.1.2 ,解决了2.1.1的一个问题,即部分实施的API被过早暴露,导致潜在的构建或运行时问题(阅读:停止使用2.1.1,立即升级到2.1.2)

  • Room 2.2.5

    2.2.5房间

  • Webkit 1.2.0, which includes the ForceDark API to control rendering WebViews in dark mode

    Webkit 1.2.0 ,其中包括ForceDark API,可在暗模式下控制渲染WebView

  • WorkManager 2.3.3 and 2.3.4

    WorkManager 2.3.3 2.3.4

Α (Alpha)

Of particular note in the many libraries hitting alpha versions recently is Activity 1.2.0-alpha02, which adds support for ActivityResultRegistry, letting you handle startActivityForResult()/ onActivityResult() and requestPermissions() / onRequestPermissionsResult() flows without overriding methods in Activity or Fragment. If you’re using this, you might also want to check out Fragment 1.3.0-alpha02, which adds support for these new APIs. Also check out the updated guide on Getting a result from an activity.

特别要注意的是,许多最近发布的Alpha版本的库是Activity 1.2.0-alpha02 ,它增加了对ActivityResultRegistry的支持,使您可以处理startActivityForResult() / onActivityResult()requestPermissions() / onRequestPermissionsResult()流,而无需覆盖Activity或分段。 如果您正在使用它,则可能还需要检出Fragment 1.3.0-alpha02 ,它增加了对这些新API的支持。 另请参阅有关从活动中获取结果的更新指南。

文章 (Articles)

Many technical articles have landed on the Android Developers publication recently, including:

最近,许多技术文章都出现在Android Developers出版物上 ,其中包括:

主题叠加 (Themes Overlay)

Nick Butcher posted the next in his series of Android Styling articles:

尼克·布彻(Nick Butcher)在他的Android样式系列文章中发布了下一篇文章:

This article covers the use of theme overlays to set a small number of attributes, which are then overlaid on top of the rest of the theme attributes in the hierarchy. Overlays are contrasted with full themes, which are used to specify a larger set of attributes, whereas overlays focus on just a small, targeted subset.

本文介绍了主题覆盖的使用,以设置少量属性,然后将这些属性覆盖在层次结构中其余主题属性的顶部。 重叠式广告与完整主题形成对比,完整主题用于指定较大的属性集,而重叠式广告仅关注较小的目标子集。

应用套件测试 (App Bundle Testing)

Ben Weiss wrote an article about how to test Android App Bundles:

Ben Weiss写了一篇有关如何测试Android App Bundle的文章:

Testing APKs is relatively straightforward; you can just send around the APK in question for your testers to install. But in the world of App Bundles, where the binary you build is not the same as the APKs downloaded from the Play Store, how can you make this process work for your testers?

测试APK相对简单。 您可以只发送有问题的APK,供测试人员安装。 但是在App Bundles的世界中,您构建的二进制文件与从Play商店下载的APK不同,那么如何使测试人员可以使用此程序呢?

Ben has you covered, with an article that details how you can upload bundles that are made available specifically for a testing audience. The article also introduces a completely new feature of Play Console — testers can now easily install historical versions of your app by following a link, so they can access the exact version that helps reproduce a bug, or they can test the in-app update flow.

Ben为您提供了一篇文章,其中详细介绍了如何上传专门供测试受众使用的捆绑软件。 本文还介绍了Play控制台的一项全新功能-测试人员现在可以通过点击链接轻松安装您应用的历史版本,这样他们就可以访问有助于重现错误的确切版本,或者可以测试应用内更新流程。

时间,枚举和R8 (When, Enums, and R8)

I posted an article in the ongoing Kotlin Vocabulary series:

我在正在进行的Kotlin词汇系列中发表了一篇文章:

This article is a subset of a presentation that I did with @Romain at KotlinConf, where we talked about how various features of Kotlin work down in the bytecode, and how the R8 compiler optimizes the inherent overhead of some of these features:

本文是我在KotlinConf上使用@Romain进行演示的一个子集,我们在其中讨论了Kotlin的各种功能如何在字节码中工作,以及R8编译器如何优化其中某些功能的固有开销:

In the case of enums, adding a switch statement (or a when statement, in Kotlin) causes the generation of an extra class and array. Using the R8 compiler can fix that.

对于枚举,添加switch语句(或Kotlin中的when语句)会导致生成额外的类和数组。 使用R8编译器可以解决此问题。

挂起修饰符-引擎盖下 (The Suspend Modifier — Under the Hood)

Manuel Vivo posted this article:

Manuel Vivo发表了这篇文章:

which explains how the Kotlin compiler transforms coroutines under the hood. (There’s also a video with similar content — see below).

这解释了Kotlin编译器如何在后台转换协程。 (还有一个具有类似内容的视频-参见下文)。

在Android 11中存储 (Storage in Android 11)

Yacine Rezgui wrote an article about external storage changes in Android 11:

Yacine Rezgui写了一篇有关Android 11中外部存储更改的文章:

This article discusses some of the large changes that were made to scoped storage in Android 10 as well as the changes intended for Android 11.

本文讨论了对Android 10中的作用域存储进行的一些大更改以及旨在用于Android 11的更改。

Kotlin协程:取消和例外 (Kotlin Coroutines: Cancellation and Exceptions)

Manuel Vivo and Florina Muntenescu posted a three-part series on cancellation and exceptions in Kotlin coroutines:

Manuel VivoFlorina Muntenescu发布了一个由三部分组成的系列,内容涉及Kotlin协程中的取消和异常:

Part 1 provides a quick overview of coroutines, including defining and explaining the necessary pieces: CoroutineScope, Job, and CoroutineContext:

第1部分快速概述了协程,包括定义和解释必要的部分:CoroutineScope,Job和CoroutineContext:

Part 2 covers (wait for it…) coroutine cancellation. The article describes how to cancel specific jobs as well as entire CoroutineScopes. It also discusses how cancellation is cooperative, and how to properly abandon work in a coroutine that has been cancelled.

第2部分介绍了(等待)协程取消。 本文介绍如何取消特定作业以及整个CoroutineScope。 它还讨论了取消是如何协作的,以及如何正确地放弃已取消的协程中的工作。

Part 3 wraps up the series by discussing what to do when things don’t go as planned: how to properly handle exceptions in your coroutine code. For example, an exception in a coroutine will, by default, cause the cancellation of all coroutines in its CoroutineScope to be canceled, but you can avoid this situation by using SupervisorJob:

第3部分通过讨论在事情未按计划进行时该怎么做来总结该系列:如何正确处理协程代码中的异常。 例如,协程中的异常默认情况下会导致取消其CoroutineScope中所有协程的取消,但是您可以通过使用SupervisorJob避免这种情况:

These articles derive from the presentation that Florina and Manuel gave at KotlinConf:

这些文章来自FlorinaManuel在KotlinConf上的演讲:

影片 (Videos)

We’ve posted a few videos recently as well:

我们最近还发布了一些视频:

辅助功能 (Accessibility)

Shailen Tuli and Lyla Fujiwara posted this video to help developers understand what to do to create accessible applications:

Shailen Tuli和Lyla Fujiwara发布了此视频,以帮助开发人员了解如何创建可访问的应用程序:

This is one of our longer-form videos that takes a full conference session and packs it into a video for easier consumption. Speaking of accessibility, the Principles for improving app accessibility guide now explains how your app is more accessible “for free” when your custom UI widgets extend from appropriate UI subclasses.

这是我们较长格式的视频之一,需要进行完整的会议讨论,并将其打包到视频中以方便使用。 说到可访问性, 《改善应用程序可访问性原则》指南现在说明了当您的自定义UI窗口小部件从相应的UI子类扩展时,如何“免费”访问您的应用程序。

Kotlin词汇 (Kotlin Vocabulary)

Three more episodes of the ongoing Kotlin Vocabulary series are now available:

正在进行的Kotlin词汇系列的另外三集现已上市:

Manuel Vivo posted Suspend functions, which explains how the Kotlin compiler transforms coroutines under the hood (this is an alternate form of the article he posted, which is discussed above):

Manuel Vivo发布了Suspend functions ,它解释了Kotlin编译器如何在后台转换协程(这是他发布的文章的替代形式,上面已经进行了讨论):

Florina Muntenescu posted Collections and sequences, which discusses when to use Kotlin collection APIs for eager evaluation, versus sequences for lazy evaluation:

Florina Muntenescu发布了Collections和sequence ,其中讨论了何时使用Kotlin集合API进行急切评估,而使用序列进行惰性评估:

Finally, I posted D8, R8, and enums, which is the video version of the When using enums and R8 article I mentioned above:

最后,我发布了D8,R8和enums ,这是我上面提到的“ 当使用枚举和R8时”文章的视频版本:

Google游戏 (Google for Games)

Like many developers and companies, we were looking forward to going to the Game Developer Summit (GDC) this year, and we’re sorry we didn’t get to see you to see you all in person. Although the event did not happen as planned, we’ve put together a virtual Google for Games Developer Summit as a cross-Google effort, and there are many new Android tools and features to cover. Things like:

与许多开发人员和公司一样,我们很期待今年参加游戏开发者峰会(GDC),但很遗憾,我们没有看到您亲自见到大家。 尽管该活动并未按计划进行,但作为跨Google的努力,我们已经组织了一次虚拟的Google for Games Developer Summit,并且涵盖了许多新的Android工具和功能。 像:

  • Native profiling capabilities are now added to Android Studio’s System Trace tool

    本机分析功能现已添加到Android Studio的系统跟踪工具中
  • Support for native debug symbols in Android Vitals to help you diagnose crashes in the field

    支持Android Vitals中的本机调试符号,以帮助您在现场诊断崩溃
  • Easier access to Google APIs for Unity developers

    方便Unity开发人员访问Google API

You can also sign up for previews such as:

您还可以注册预览,例如:

  • A game development extension for Visual Studio to make it easier to add Android support to your cross-platform game

    Visual Studio的游戏开发扩展,可以更轻松地向跨平台游戏添加Android支持
  • A new Android GPU inspector tool

    新的Android GPU检查器工具

There’s an article on the Android Developers Blog that gives an overview of the various things that we’ve announced and released. There’s also a Google for Games Developer Summit playlist on YouTube with the keynote and a host of technical sessions from Google.

Android开发者博客上一篇文章,概述了我们宣布和发布的各种产品。 YouTube上还有一个Google for Games Developer Summit播放列表 ,包含主题演讲和Google举办的许多技术会议。

亚行播客节目 (ADB Podcast Episodes)

There have been a couple of episodes of Android Developers Backstage posted since the last Now in Android. Check them out at the links below, or in your favorite podcast client:

自从上次在Android中发布Now之后,已经发布了几集Android Developers Backstage。 在下面的链接或您喜欢的播客客户端中查看它们:

In which I talked with Amith Yamasani, Makoto Onuki, and Kweku Adams from the framework team about power management. We waxed poetic about the heuristics the system uses to kill tasks, doze mode and how the system tries to save battery, TrimMemory requests, JobScheduler (the underlying platform facility used by WorkManager), AppStandby buckets, and more.

在其中,我与框架团队的Amith Yamasani,Makoto Onuki和Kweku Adams讨论了电源管理。 我们对系统用于终止任务,打ze模式以及系统如何节省电池,TrimMemory请求,JobScheduler(WorkManager使用的基础平台工具),AppStandby存储桶等的启发式方法充满诗意。

In which I talked with Sumir Kataria and Rahul Ravikumar from the Android Toolkit team about Work Manager, an AndroidX library for deferrable background work. We talked about recent changes such as on demand initialization, new lint checks, and more.

在其中,我与Android Toolkit团队的Sumir KatariaRahul Ravikumar讨论了工作管理器(WorkManager),这是一个用于延迟背景工作的AndroidX库。 我们讨论了最近的更改,例如按需初始化,新的皮棉检查等。

接着… (Now then…)

That’s it for this time. So go learn about Android 11 DP2! Check out the CameraX beta release and other AndroidX releases! Find a slew of new technical articles and videos on the Android Developers publication and YouTube channel! See what’s happening in the world of Android game development! Check out the latest ADB podcast episodes! And come back here soon for the next update from the Android developer universe.

这次就是这样。 因此,去了解Android 11 DP2吧! 查看CameraX beta版本和其他AndroidX版本 ! 在Android Developers出版物YouTube频道上找到大量的新技术文章和视频! 看看Android游戏开发世界正在发生什么! 查看最新的亚行播客节目 ! 并很快返回此处,以获取Android开发人员环境的下一个更新。

翻译自: https://medium.com/androiddevelopers/now-in-android-14-78a91def4962

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值