首页指南参考教程

Expo

了解 Expo Go,这是一款免费的开源沙盒应用,用于在 Android 和 iOS 上学习和试验 React Native。


Expo 是一个免费的 open-source 沙箱,用于在 Android 和 iOS 设备上学习和试验 React Native。你可以直接从应用商店安装它,并在几分钟内启动并运行 - 无需安装原生工具链并编译应用。

¥Expo Go is a free, open-source sandbox for learning and experimenting with React Native on Android and iOS devices. You can install it directly from app stores, and get up and running within minutes — no need to install a native toolchain and compile an app.

不建议使用 Expo Go 来构建生产质量的应用 - 请使用 开发构建。也不推荐用于 部署/分发应用。也就是说,你在 Expo Go 中工作时学到的所有内容都可以转移到开发构建中,当你想在快速的新项目沙箱中尝试新想法时,你很可能会在你的旅程中回到 Expo Go。这是一个很好的起点!

¥Expo Go is not recommended for building production-quality apps — use development builds instead. It's also not recommended for deploying/distributing apps. That said, everything you learn while working in Expo Go will be transferable to development builds, and you're likely to come back to Expo Go along your journey when you want to try new ideas in a quick new project sandbox. It's a great place to start!

在你的设备上安装 Expo Go

¥Install Expo Go on your device

它可在 Android Play 商店和 iOS App Store 上使用。

¥It is available on both the Android Play Store and iOS App Store.

  • Android Play 商店 - Android Lollipop (5) 及更高版本

    ¥Android Play Store - Android Lollipop (5) and greater

  • iOS 应用商店 - iOS 13 及更高版本

    ¥iOS App Store - iOS 13 and greater

当你在项目中运行 npx expo start 时,Expo CLI 会启动 开发服务器 并生成二维码。在 Android 上,你可以在设备上打开 Expo Go 应用并扫描二维码以连接到开发服务器。在 iOS 上,使用设备的相机扫描 QR 码。

¥When you run npx expo start in your project, Expo CLI starts a development server and generates a QR code. On Android, you can open the Expo Go app on your device and scan the QR code to connect to the dev server. On iOS, use the device's camera to scan the QR code.

Terminal
npx expo start
Want to understand how Expo Go works?

当 Expo Go 连接到开发服务器时,服务器会返回描述该项目的 JSON 清单文件。Expo Go 使用此清单下载 JavaScript 包以及运行项目所需的任何资源。然后,JavaScript 引擎 执行此 JavaScript 包来渲染 React Native 应用。

¥When Expo Go connects to the dev server, the server returns a JSON manifest file that describes the project. Expo Go uses this manifest to download the JavaScript bundle and any assets required to run the project. Then, the JavaScript engine executes this JavaScript bundle to render the React Native app.

该清单类似于网络上的 index.html。它由根 URL / 提供,并允许从 bundleUrl 下载项目脚本代码。可以使用应用配置(app.json、app.config.js)自定义清单。iconsplash 等其他字段可用于自定义 Expo Go 或 expo-dev-client 渲染应用的方式。

¥The manifest is similar to an index.html on the web. It is served from the root URL / and allows downloading the project script code from bundleUrl. The manifest can be customized using the app config (app.json, app.config.js). Additional fields like icon and splash can be used to customize how Expo Go or expo-dev-client presents the app.

{
  "name": "My New Project",
  "entryPoint": "index.js",
  "bundleUrl": "http://localhost:8081/index.bundle?platform=ios"
}

SDK 版本

¥SDK versions

Expo Go 支持多个 SDK 版本。新的 Expo SDK 版本每年大约发布 3 次。每次将新版本添加到 Expo Go 时,都会删除旧版本。你可以通过导航到设置页面在 Expo Go 应用中查看支持的 SDK 版本。

¥Expo Go supports multiple SDK versions. A new Expo SDK version is released approximately three times each year. Each time a new version is added to Expo Go, an old version is dropped. You can see the supported SDK versions in the Expo Go app by navigating to the settings page.

What if I open a project with an unsupported SDK version?

在 Expo Go 中运行为不受支持的 SDK 版本创建的项目时,你将看到以下错误:

¥When running a project that was created for an unsupported SDK version in Expo Go, you'll see the following error:

"Project is incompatible with this version of Expo Go"

要解决此问题,强烈建议将你的项目升级到 支持的 SDK 版本。如果你想了解如何操作,请参阅 将项目升级到新的 SDK 版本

¥To fix this, upgrading your project to a supported SDK version is highly recommended. If you want to learn how to do it, see Upgrade the project to a new SDK Version.

How do I upgrade my project from an unsupported SDK version?

有关升级到特定 SDK 版本的说明,请参阅 Expo SDK 升级指南

¥See Upgrading Expo SDK guide for instructions for upgrading to a specific SDK version.

How can I install an older version of Expo Go to run my project?

如果你无法将项目升级到较新的 SDK 版本,你仍然可以使用旧版本的 Expo Go 运行它。但是,此方法不适用于物理 iOS 设备,因为无法直接安装应用(旁加载)。如果你需要在物理 iOS 设备上运行项目,请考虑创建 开发构建

¥If you cannot upgrade your project to a newer SDK version, you can still run it using an older version of Expo Go. However, this method will not work for physical iOS devices because it is impossible to install apps directly (sideload). If you need to run your project on a physical iOS device, consider creating a development build.

如果你尝试在物理 Android 设备上使用此方法,请将其连接到你的计算机并启用 USB 调试选项。

¥If you are trying to use this method on a physical Android device, connect it to your computer and enable the USB Debugging option.

要在模拟器或模拟器上运行它,请参阅 安卓模拟器iOS 模拟器

¥To run it on an emulator or a simulator, see Android emulators and iOS simulators.

1

If installed, remove Expo Go from your device or simulator.

2

启动开发服务器:

¥Start the development server:

Terminal
npx expo start

3

ai 在 Android 或 iOS 上运行你的应用。这将在你的设备/模拟器上下载并安装兼容的 Expo Go,并在客户端中打开你的项目。

¥Press a or i to run your app on Android or iOS. This will download and install the compatible Expo Go on your device/simulator and open your project in the client.

Expo Go 的兼容版本将自动安装在你的设备或模拟器上,并且你的项目将打开。

¥A compatible version of Expo Go will be automatically installed on your device or simulator, and your project will open.

使用你的 Expo 账户登录

¥Log in with your Expo account

安装完成后打开 Expo Go 应用。如果你有 使用 Expo CLI 创建了一个账户,则可以通过单击“主页”选项卡顶部标题中的“登录”按钮来登录。登录后,你可以在开发项目时更轻松地在 Expo Go 应用中打开项目 - 它们将自动显示在应用“主页”选项卡上的“项目”部分下。

¥Open the Expo Go app after it has finished installing. If you have created an account with Expo CLI, you can sign in by clicking the Log In button in the top header on the Home tab. Signing in will make it easier for you to open projects in the Expo Go app while developing them — they will appear automatically under the Projects section on the Home tab of the app.

有时,直接在计算机上运行应用而不是在单独的物理设备上运行应用可能会很有用。如果你想进行此设置,你可以了解有关安装 安卓模拟器iOS 模拟器(仅限 macOS) 的更多信息。

¥Sometimes, it can be useful to run your app directly on your computer instead of on a separate physical device. If you would like to set this up, you can learn more about installing an Android Emulator and an iOS Simulator (macOS only).

Expo 中文网 - 粤ICP备13048890号