Reference version

This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo DevClient iconExpo DevClient

一个用于创建开发版本并包含实用开发工具的库

Android
iOS
tvOS
Recommended version:
~58.0.1

expo-dev-client 为调试版本添加了各种实用的开发工具:

Expo 文档将包含 expo-dev-client 的调试版本称为开发版本。

安装

Terminal
- npx expo install expo-dev-client
- yarn expo install expo-dev-client
- pnpm expo install expo-dev-client
- bun expo install expo-dev-client

使用 EAS Build 创建版本时,请在 eas.json 中的构建配置文件上将 developmentClient 设置为 true。如果不设置,EAS Build 将生成不包含开发工具的独立版本。例如:

eas.json
{ "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中的说明操作。

在应用配置中进行配置

如果你的项目使用配置插件(Continuous Native Generation(CNG)),则可以使用其内置的配置插件配置开发客户端启动器。该插件允许你配置各种无法在运行时设置、且必须构建新的应用二进制文件才能生效的属性。如果你的应用不使用 CNG,则需要手动配置此库。

Example app.json with config plugin

app.json
{ "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

NameDefaultDescription
launchMode"most-recent"

Determines whether to launch the most recently opened project or navigate to the launcher screen.

  • most-recent - Attempt to launch directly into a previously opened project and if unable to connect, fall back to the launcher screen.
  • launcher - Opens the launcher screen.
addGeneratedSchemetrue

By default, expo-dev-client will register a custom URL scheme to open a project. Set this property to false to disable this scheme.

defaultLaunchURL-

Launch directly into this URL instead of navigating to launcher screen. If launchMode is set to most-recent, then launcher will use the defaultLaunchURL as a fallback.

toolsButtontrue

Whether to show the floating tools button by default. Use setToolsButtonVisible from expo-dev-client to change it at runtime.

skipOnboardingfalse

Skip the onboarding screen that shows in the dev menu on the first launch of the app.

showMenuAtLaunchtrue

Show the developer menu immediately after launching the app.

TV 支持

  • Android TV:支持所有操作,与 Android 手机类似
  • Apple TV:支持使用本地或隧道打包器进行基本操作。目前尚不支持向 EAS 进行身份验证以及列出 EAS 版本和更新

API

import * as DevClient from 'expo-dev-client';

Methods

DevClient.closeMenu()

Android
iOS
tvOS

A method that closes development client menu when called.

Returns:
void

DevClient.hideMenu()

Android
iOS
tvOS

A method that hides development client menu when called.

Returns:
void

DevClient.openMenu()

Android
iOS
tvOS

A method that opens development client menu when called.

Returns:
void

DevClient.registerDevMenuItems(items)

Android
iOS
tvOS
ParameterType
itemsExpoDevMenuItem[]

A method that allows to specify custom entries in the development client menu.

Returns:
Promise<void>

DevClient.setToolsButtonVisible(visible)

Android
iOS
tvOS
ParameterType
visibleboolean

Sets whether the floating tools button is visible.

Returns:
void

Types

ExpoDevMenuItem

Android
iOS
tvOS

An object representing the custom development client menu entry.

PropertyTypeDescription
callback() => void

Callback to fire, when user selects an item.

namestring

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