参考


Expo SDK 以包的形式提供对设备和系统功能的访问,例如联系人、相机、陀螺仪、GPS 位置等。你可以使用 npx expo install 命令安装任何 Expo SDK 包。例如,可以使用以下命令安装三个不同的包:

🌐 The Expo SDK provides access to device and system functionality such as contacts, camera, gyroscope, GPS location, and so on, in the form of packages. You can install any Expo SDK package using the npx expo install command. For example, three different packages are installed using the following command:

Terminal
npx expo install expo-camera expo-contacts expo-sensors

安装一个或多个包后,你可以将它们导入你的 JavaScript 代码中:

🌐 After installing one or more packages, you can import them into your JavaScript code:

import { CameraView } from 'expo-camera'; import * as Contacts from 'expo-contacts'; import { Gyroscope } from 'expo-sensors';

这允许你编写 Contacts.getContactsAsync() 并从设备读取联系人,读取陀螺仪传感器以检测设备移动,或启动手机相机拍照。

🌐 This allows you to write Contacts.getContactsAsync() and read the contacts from the device, read the gyroscope sensor to detect device movement, or start the phone's camera and take photos.

所有 Expo SDK 包都可以在任何 React Native 应用中使用

🌐 All Expo SDK packages work in any React Native app

Expo 应用是 React Native 应用,因此所有 Expo SDK 包在安装并配置了 expo 包的任何 React Native 应用中都可以使用。创建支持 Expo SDK 包的 React Native 应用最简单的方法是使用 create-expo-app。不过,你也可以通过 npx install-expo-modules 命令将 Expo SDK 支持添加到现有的 React Native 应用中。

🌐 Expo apps are React Native apps, so all Expo SDK packages work in any React Native app with the expo package installed and configured. The easiest way to create a React Native app with support for Expo SDK packages is to use create-expo-app. However, you can also add Expo SDK support to an existing React Native app with the npx install-expo-modules command.

Terminal
# Create a project named my-app
npx create-expo-app my-app --template bare-minimum
在现有的 React Native 应用中安装 Expo SDK 包

了解更多关于使用 npx @react-native-community/cli@latest init 创建的项目配置到 Expo SDK 包的信息。

使用库

了解如何在项目中安装 Expo SDK 包。

使用预发布版本

🌐 Using pre-release versions

新的 Expo SDK 版本每年发布三次。在这些版本之间,我们会发布 expo 包以及所有 Expo SDK 包的预发布版本。预发布版本不被视为稳定版本,仅当你能够接受遇到错误或其他问题的风险时才应使用。

🌐 New Expo SDK versions are released three times each year. Between these releases, we publish pre-release versions of the expo package and all of the Expo SDK packages. Pre-releases are not considered stable and should only be used if you are comfortable with the risk of encountering bugs or other issues.

体验发布

🌐 Canary releases

预览版发布代表在发布时 main 分支状态的快照。预览版包版本在名称中包含 -canary,以及日期和提交哈希,例如 54.0.0-canary-20240418-8d74597。要安装最新的预览版版本:

🌐 Canary releases represent a snapshot of the state of the main branch at the time they are published. Canary package versions include -canary in the name, along with the date and commit hash, such as 54.0.0-canary-20240418-8d74597. To install the latest canary release:

Terminal
# Install the alpha version of expo and its related packages
npm install expo@canary && npx expo install --fix

你通常可以在 Expo SDK 的稳定版本中使用单个包的预发布版本。在预览版版本中,有时可能会出现不兼容或其他问题。如果你选择使用预览版包,并且在确认它能够很好地满足你的使用需求之后,你可能需要关闭依赖验证警告

🌐 You can often use pre-release versions of individual packages with stable releases of the Expo SDK. There may occasionally be incompatibilities or other issues that arise in canary-quality releases. You may want to silence dependency validation warnings if you opt in to the canary package and once you have verified that it works well for your use cases.

测试版发布

🌐 Beta releases

在每次 Expo SDK 发布之前,我们会发布 expo 包和所有 Expo SDK 包的测试版。测试版被认为比 Canary 版本稳定得多,我们鼓励开发者在他们的应用上尝试这些版本并分享反馈。测试版在 npm 上使用 beta 标签,并遵循相关 更新日志 文章中的说明。

🌐 Before each Expo SDK release, we publish beta versions of the expo package and all of the Expo SDK packages. Beta releases are considered much more stable than canary releases, and we encourage developers to try them out on their apps and share their feedback. Beta releases use the beta tag on npm and follow the instructions in the related changelog post.

每个 Expo SDK 版本都依赖于 React Native 版本

🌐 Each Expo SDK version depends on a React Native version

Expo SDK versionReact Native versionReact versionReact Native Web versionReact Native TV version
Minimum Node.js version
54.0.00.8119.1.00.21.00.81-stable20.19.x
53.0.00.7919.0.00.20.00.79-stable20.18.x
52.0.00.7618.3.10.19.130.77-stable20.18.x

附加信息

🌐 Additional information

Expo SDK 关于跟踪 React Native 版本的政策
  • Expo SDK 版本每年发布三次,每个 Expo SDK 版本针对一个 React Native 版本。通常,这会是发布时的最新稳定版本。
  • React Native 的发布节奏在其发展过程中有所不同,目前计划在 2025 年发布六个版本。在这一节奏下,你可以预计每第二个 React Native 版本都会对应一个 Expo SDK 版本。
  • 即将发布的 Expo SDK 预发布版本将快速支持最新版本的 React Native,通常在其发布当天即可支持。Expo SDK 团队的一名成员参与了每个版本的 React Native 发布团队,负责在 Expo 仓库中持续更新 React Native 版本,验证兼容性,并将回归问题反馈给 Meta 团队。
为什么不在每次 React Native 发布时立即发布新的 Expo SDK 版本?

在 Expo,我们发现发布三个主要版本能够为依赖我们的开源工具的开发者提供稳定性和创新性的良好平衡。Expo 与 Meta 在发布方面密切合作,我们将继续改进流程,以尽快将最新的 Expo 和 React Native 功能带给你们。

🌐 At Expo, we have found that releasing three major version provides a good balance of stability and innovation for developers depending on our open source tools. Expo and Meta work closely together on releases, and we will keep improving our processes to get the latest Expo and React Native features to you as quickly as possible.

如果我需要使用最新的 React Native 版本,但它还没有出现在 Expo SDK 版本中,该怎么办?

We work closely with the team at Meta to ensure that any urgent fixes are included in the React Native version used by the latest Expo SDK. If your issue won't be cherrypicked into an existing release because it is more niche, or it involves a breaking change, then you have two options:

  1. 使用 patch-package 来引入修复。
  2. 使用 Expo SDK 的预发布版本。一个 (示例)。
我可以在最新的 Expo SDK 中使用旧版本的 React Native 吗?

Expo SDK 中的包旨在支持该 SDK 的目标 React Native 版本。通常,它们不支持旧版本的 React Native,但有时可能支持。当发布新的 React Native 版本时,Expo SDK 包的最新版本通常会更新以支持它。然而,这可能需要几周或更长时间,具体取决于该版本更改的范围。

🌐 Packages in the Expo SDK are intended to support the target React Native version for that SDK. Typically, they will not support older versions of React Native, but they may. When a new version of React Native is released, the latest versions of the Expo SDK packages are typically updated to support it. However, this may take weeks or more, depending on the extent of the changes in the release.

支持 Android 和 iOS 版本

🌐 Support for Android and iOS versions

每个版本的 Expo SDK 都支持最低的 Android 和 iOS 操作系统版本。对于 Android,定义了 compileSdkVersion,它告诉 Gradle 使用哪个 Android SDK 版本来编译应用。这也意味着你可以使用该 SDK 版本以及之前版本中包含的 Android API 功能。对于 iOS,Xcode 指定了用于编译应用的最低 Xcode SDK 版本。

🌐 Each version of Expo SDK supports a minimum OS version of Android and iOS. For Android, the compileSdkVersion is defined which tells the Gradle which Android SDK version to use to compile the app. This also means that you can use the Android API features included in that SDK version and from the previous versions. For iOS, the Xcode tells the minimum Xcode SDK version to use to compile the app.

Expo SDK versionAndroid versioncompileSdkVersiontargetSdkVersioniOS versionXcode version
54.0.07+363615.1+16.1+
53.0.07+353515.1+16.0+
52.0.07+353415.1+16.0+

在决定是否升级你的 Expo SDK 版本时,请同时考虑 Expo 的 SDK 版本和应用商店提交要求,如上表所示。Google Play 商店和 Apple App Store 会定期提高其最低要求的操作系统版本和 API 级别,这些都是新应用提交所必须的。Expo 无法控制应用商店的要求,你应查看 GoogleApple 以获取当前的商店提交要求。

🌐 When deciding whether to upgrade your Expo SDK version, consider both Expo's SDK version and app store submission requirements, as described in the above table. Google Play Store and Apple App Store periodically increase their minimum required OS versions and API levels, which are required for new app submissions. Expo has no control over the app store requirements, and you should check Google and Apple for the current store submission requirements.