在现有 React Native 项目中安装 expo-dev-client

了解如何在现有的 React Native 项目中安装和配置 expo-dev-client。


以下指南说明了如何在现有的 React Native 项目中安装和配置 expo-dev-client

🌐 The following guide explains how to install and configure expo-dev-client in an existing React Native project.

你需要创建一个新项目吗?

如果你要开始一个新项目,请使用 with-dev-client 模板创建它:

🌐 If you're starting with a new project, create it using the with-dev-client template:

Terminal
npx create-expo-app -e with-dev-client
你在项目中使用连续本地生成(CNG)吗?

要在使用 CNG 的项目中使用 expo-dev-client,请参见 创建开发版本

🌐 To use expo-dev-client in a project that uses CNG, see Create a development build.

先决条件

🌐 Prerequisites

必须安装并配置 expo 包。 如果你是使用 npx @react-native-community/cli@latest init 创建的项目,并且没有安装任何其他 Expo 库,则需要在继续之前安装 Expo 模块

1

安装 expo-dev-client

🌐 Install expo-dev-client

expo-dev-client 库添加到你的 package.json 中:

🌐 Add the expo-dev-client library to your package.json:

Terminal
npx expo install expo-dev-client

如果你的项目在磁盘上有一个 ios 目录,请运行以下命令以完整安装 expo-dev-client 的原生代码:

🌐 If your project has an ios directory on disk, run the following command to fully install the native code for expo-dev-client:

Terminal
npx pod-install

如果你的项目没有 ios 目录,你可以跳过这一步。

🌐 If your project doesn't have an ios directory, you can skip this step.

2

配置深层链接

🌐 Configure deep links

Expo CLI 使用深度链接来启动你的项目,如果你计划 使用 expo-dev-client 启动预览更新,并且已经向你的项目添加了自定义深度链接方案,这也会很有用。

🌐 Expo CLI uses a deep link to launch your project, and it's also useful if you use plan to use expo-dev-client for launching preview updates if you have added a custom deep link scheme to your project.

如果你还没有为你的应用配置 scheme 来支持深度链接,那么可以使用 uri-scheme 库来帮你实现这一功能。

🌐 If you haven't configured a scheme for your app yet to support deep linking, then use uri-scheme library to do this for you.

Terminal
# List your project's schemes
npx uri-scheme list

# Add a scheme to your project
npx uri-scheme add your-scheme

欲了解更多信息,请参阅 uri-scheme

🌐 For more information, see the uri-scheme library.

3

构建并安装应用

🌐 Build and install the app

使用你选择的工具创建应用的调试版本。例如,你可以在本地使用 Expo CLI 或者 在云端使用 EAS Build 来完成此操作。

🌐 Create a debug build of your app using the tools of your choice. For example, you can do this locally with Expo CLI or in the cloud with EAS Build.