This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
Expo 开发客户端
一个允许创建开发构建并包含实用开发工具的库。
expo-dev-client 会为你的调试构建添加各种有用的开发工具:
- 可配置的启动器界面,因此你可以启动更新(例如来自 PR 预览的更新),并在不同的开发服务器之间切换,而无需重新编译原生应用
- 改进的调试工具(例如支持检查网络请求)
- 功能强大且可扩展的开发者菜单界面
Expo 文档中将包含 expo-dev-client 的调试构建称为 开发构建。
安装
- npx expo install expo-dev-client当你使用 EAS Build 创建构建时,请在 eas.json 中的某个构建配置文件里将 developmentClient 设置为 true。如果不这样做,EAS Build 会生成一个不包含开发工具的独立构建。例如:
{ "build": { "development": { "developmentClient": true, "distribution": "internal" %%placeholder-start%%... %%placeholder-end%% } } %%placeholder-start%%... %%placeholder-end%% }
有关更多信息,请参阅 eas.json 参考中的 developmentClient 属性。
如果你要在现有的 React Native 应用中安装此功能,请先在你的项目中安装 expo。然后,按照在现有 React Native 项目中安装 expo-dev-client中的说明进行操作。
在 app config 中配置
如果你在项目中使用 config plugins([连续原生生成(CNG)](/workflow/continuous-native-generation/)),可以使用其内置的config plugin来配置开发客户端启动器。该插件允许你配置各种无法在运行时设置的属性,并且这些属性需要构建新的应用二进制文件才能生效。如果你的应用不使用 CNG,那么你需要手动配置该库。
Example app.json with config plugin
{ "expo": { "plugins": [ [ "expo-dev-client", { "launchMode": "most-recent", "defaultLaunchURL": "http://localhost:8081", "android": { "defaultLaunchURL": "http://10.0.2.2:8081" }, "toolsButton": true, "skipOnboarding": false, "showMenuAtLaunch": true } ] ] } }
Configurable properties
| Name | Default | Description |
|---|---|---|
launchMode | "most-recent" | 决定是启动最近打开的项目,还是进入启动器屏幕。
|
addGeneratedScheme | true | 默认情况下, |
defaultLaunchURL | - | 直接启动到此 URL,而不是进入启动器屏幕。
如果 |
toolsButton | true | 是否显示浮动工具按钮。 |
skipOnboarding | false | 跳过应用首次启动时在开发者菜单中显示的引导屏幕。 |
showMenuAtLaunch | true | 在启动应用后立即显示开发者菜单。 |
TV 支持
- Android TV: 所有操作都受支持,类似于 Android 手机。
- Apple TV: 支持使用本地或隧道式 packager 进行基本操作。当前尚不支持 EAS 认证,以及 EAS 构建和更新列表。
API
import * as DevClient from 'expo-dev-client';
Methods
A method that closes development client menu when called.
voidA method that hides development client menu when called.
voidA method that opens development client menu when called.
void| Parameter | Type |
|---|---|
| items | ExpoDevMenuItem[] |
A method that allows to specify custom entries in the development client menu.
Promise<void>Types
An object representing the custom development client menu entry.
| Property | Type | Description |
|---|---|---|
| callback | () => void | Callback to fire, when user selects an item. |
| name | string | Name of the entry, will be used as label. |
| shouldCollapse(optional) | boolean | A boolean specifying if the menu should close after the user interaction. Default: false |