了解如何在裸 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:
-
npx create-expo-app -e with-dev-client
要在使用 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 init
创建了项目并且没有安装任何其他 Expo 库,则在继续之前需要 安装 Expo 模块。
¥The expo
package must be installed and configured. If you created your project with npx react-native init
and do not have any other Expo libraries installed, you will need to install Expo modules before proceeding.
1
¥Install expo-dev-client
将 expo-dev-client
库添加到 package.json 中:
¥Add the expo-dev-client
library to your package.json:
-
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
:
-
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.
# 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
¥Add additional optional configuration
对于某些类型的错误,你可以在使用 expo-dev-client
时获得更有用的错误消息。要启用此功能,请在项目的索引文件中导入 expo-dev-client
。确保在导入应用的 JS 代码之前尽早执行导入语句(将导入置于 import App from './App'
上方)。
¥For certain types of errors, you can obtain more helpful error messages when using expo-dev-client
. To turn this on, import expo-dev-client
in the project's index file. Make sure that the import statement is executed early, before your application's JS code is imported (place the import above import App from './App'
).
import 'expo-dev-client';
%%placeholder-start%%... %%placeholder-end%%
import App from './App';
欲了解更多信息,请参阅 错误处理。
¥For more information, see Error handling.
4
¥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.