首页指南参考教程

参考


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

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

¥Each Expo SDK version depends on a React Native version

大约每四个月就会发布一个新的 Expo SDK 版本,通常会更新到 React Native 和 React Native Web 的最新稳定版本,并包括对 Expo SDK 的各种错误修复、功能和改进。

¥Approximately every four months there is a new Expo SDK release that typically updates to the latest stable versions of React Native and React Native Web, and includes a variety of bug fixes, features, and improvements to the Expo SDK.

Expo SDK 版本React Native 版本React Native 网页版
51.0.00.740.19.10
50.0.00.730.19.6
49.0.00.720.19.6

支持其他 React Native 版本

¥Support for other React Native versions

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 功能。

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

Expo SDK 版本安卓版本compileSdkVersioniOS 版本
51.0.06+3413.4+
50.0.06+3413.4+
49.0.05+3313+