参考


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 包

Learn more about configuring projects created with npx @react-native-community/cli@latest init to Expo SDK packages.

使用库

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

使用预发布版本

¥Using pre-release versions

新的 Expo SDK 版本每年发布 3 次。在这些版本之间,我们发布了 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 软件包版本的名称中包含 -canary,以及日期和提交哈希,例如 51.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 51.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 包的测试版。Beta 版本被认为比 Canary 版本稳定得多,我们鼓励开发者在他们的应用上试用它们并分享他们的反馈。Beta 版本在 npm 上使用 beta 标签,并按照相关 changelog 帖子中的说明进行操作。

¥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.

附加信息

¥Additional information

Expo SDK policy for tracking React Native releases
  • Expo SDK versions are released three times each year, and each Expo SDK release targets a single React Native version. This is typically the latest stable version at the time of the release.
  • The release cadence of React Native has varied over its history and it is currently on pace for six releases in 2025. While on this cadence, you can expect that there will be an Expo SDK version for every second React Native release.
  • Pre-release versions of the upcoming Expo SDK will include support for the latest version of React Native quickly, usually the same day it is released. A member of the Expo SDK team works on the React Native releases team for each release, and is responsible for continuously updating the React Native version in the Expo repository, verifying compatibility, and reporting regressions back to the team at Meta.
Why not release a new Expo SDK version immediately for every React Native release?

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.

What if I need a change from the latest React Native version and it's not yet in an Expo SDK release?

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. Use patch-package to pull in the fix.
  2. Use a pre-release version of the Expo SDK. An (example).
Can I use an older version of React Native with the latest 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 版本安卓版本compileSdkVersioniOS 版本Xcode 版本
52.0.07+3515.1+16.0+
51.0.06+3413.4+15.4
50.0.06+3413.4+15.4

在决定是否升级 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.