Reference version

This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 55).

Expo DevClient iconExpo DevClient

一个允许创建开发构建并包含实用开发工具的库。

Android
iOS
tvOS

For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.

expo-dev-client 会为你的调试构建添加各种有用的开发工具:

Expo 文档将包含 expo-dev-client 的调试构建称为 开发构建

安装

Terminal
npx expo install expo-dev-client

如果你要在一个现有的 React Native 应用中安装它,请先在你的项目中安装 expo。然后,按照在现有 React Native 项目中安装 expo-dev-client中的说明进行操作。

在 app config 中配置

如果你在项目中使用 config plugins([连续原生生成(CNG)](/workflow/continuous-native-generation/)),可以使用其内置的config plugin来配置 development client launcher。该插件允许你配置各种无法在运行时设置的属性,并且这些属性需要构建新的应用二进制文件才能生效。如果你的应用使用 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.0.2:8081" } } ] ] } }

Configurable properties

NameDefaultDescription
launchMode"most-recent"

决定是启动最近打开的项目,还是进入启动器屏幕。

  • most-recent - 尝试直接启动到之前打开的项目,如果无法连接,则回退到启动器屏幕。
  • launcher - 打开启动器屏幕。
addGeneratedSchemetrue

默认情况下,expo-dev-client 会注册一个自定义 URL scheme 来打开项目。将此属性设为 false 可禁用该 scheme。

defaultLaunchURL-

直接启动到此 URL,而不是进入启动器屏幕。 如果 launchMode 设置为 most-recent,则启动器会将 defaultLaunchURL 作为回退。

android.launchMode"most-recent"
Only for:
Android

决定在 Android 上是启动最近打开的项目还是进入启动器屏幕。仅为 Android 覆盖顶层的 launchMode 设置。

  • most-recent - 尝试直接启动到之前打开的项目,如果无法连接,则回退到启动器屏幕。
  • launcher - 打开启动器屏幕。
ios.launchMode"most-recent"
Only for:
iOS

决定在 iOS 上是启动最近打开的项目还是进入启动器屏幕。仅为 iOS 覆盖顶层的 launchMode 设置。

  • most-recent - 尝试直接启动到之前打开的项目,如果无法连接,则回退到启动器屏幕。
  • launcher - 打开启动器屏幕。
android.defaultLaunchURL-
Only for:
Android

不是进入启动器屏幕,而是直接启动到此 URL。 如果 launchMode 设置为 most-recent,则启动器会将 defaultLaunchURL 作为回退。

ios.defaultLaunchURL-
Only for:
iOS

不是进入启动器屏幕,而是直接启动到此 URL。 如果 launchMode 设置为 most-recent,则启动器会将 defaultLaunchURL 作为回退。

TV 支持

  • 此库仅在 SDK 54 及更高版本中支持 TV。
    • Android TV:支持所有操作,类似于 Android 手机。
    • Apple TV:支持使用本地或隧道 packager 的基本操作。尚不支持对 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>

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