首页指南参考教程

使用开发版本

了解如何使用项目的开发版本。


通常,从头开始创建新的原生构建需要很长时间,以至于你可能会想切换任务并失去注意力。但是,在你的设备或模拟器/模拟器上安装了开发版本后,你无需等待原生构建过程,直到你 更改底层原生代码 为你的应用提供支持。

¥Usually, creating a new native build from scratch takes long enough that you'll be tempted to switch tasks and lose your focus. However, with the development build installed on your device or an emulator/simulator, you won't have to wait for the native build process until you change the underlying native code that powers your app.

添加错误处理

¥Add error handling

某些类型的错误可以提供比 React Native 默认附带的错误消息更有用的错误消息。要开启此功能,需要在 App.{js|tsx} 或 app/_layout.tsx 顶部导入 expo-dev-client

¥Certain types of errors can provide more helpful error messages than the ones that ship by default with React Native. To turn this feature on, you need to import expo-dev-client at the top of the App.{js|tsx} or app/_layout.tsx.

App.js
import 'expo-dev-client';

这只会影响你进行此更改的应用。如果你想从单个开发应用加载多个项目,则需要将此导入语句添加到每个项目中。

¥This will only affect the application in which you make this change. If you want to load multiple projects from a single development app, you'll need to add this import statement to each project.

启动开发服务器

¥Start the development server

要开始开发,请运行以下命令来启动开发服务器:

¥To start developing, run the following command to start the development server:

Terminal
npx expo start

要在开发客户端中打开项目:

¥To open the project inside your development client:

  • ai 键在 Android 模拟器或 iOS 模拟器上打开你的项目。

    ¥Press a or i keys to open your project on an Android Emulator or an iOS Simulator.

  • 在物理设备上,通过系统摄像头或 QR 码阅读器扫描 QR 码,以在设备上打开项目。

    ¥On a physical device, scan the QR code from your system's camera or a QR code reader to open the project on your device.

启动器屏幕

¥The launcher screen

如果你从设备的主屏幕启动开发版本,你将看到启动器屏幕,如下所示:

¥If you launch the development build from your device's Home screen, you will see your launcher screen, which looks similar to the following:

如果在你的本地网络上检测到打包程序,或者你已在 Expo CLI 和开发版本中登录 Expo 账户,则可以直接从此屏幕连接到它。否则,你可以通过扫描 Expo CLI 显示的二维码进行连接。

¥If a bundler is detected on your local network, or if you have signed in to an Expo account in both Expo CLI and your development build, you can connect to it directly from this screen. Otherwise, you can connect by scanning the QR code displayed by the Expo CLI.

重建开发版本

¥Rebuild a development build

如果你向项目添加包含原生代码 API 的库(例如 expo-secure-store),则必须重新构建开发客户端。这是因为当将库作为项目的依赖安装时,库的原生代码不会自动包含在开发客户端中。

¥If you add a library to your project that contains native code APIs, for example, expo-secure-store, you will have to rebuild the development client. This is because the native code of the library is not included in the development client automatically when installing the library as a dependency on your project.

调试开发版本

¥Debug a development build

当你需要时,你可以通过在 Expo CLI 中按 Cmd ⌘ + dCtrl + d 或摇动手机或平板电脑来访问菜单。在这里,你将能够访问开发版本的所有功能、你需要的任何调试功能,或者切换到应用的不同版本。

¥When you need to, you can access the menu by pressing Cmd ⌘ + d or Ctrl + d in Expo CLI or by shaking your phone or tablet. Here you'll be able to access all of the functions of your development build, any debugging functionality you need, or switch to a different version of your app.

有关详细信息,请参阅 调试 指南。

¥See Debugging guide for more information.

Expo 中文网 - 粤ICP备13048890号