工作流程

了解不同的工作流程,例如使用 Expo 工具构建应用的托管工作流程和裸工作流程。


使用 Expo 工具构建应用的两种方法称为托管工作流和裸工作流。

¥The two approaches to building applications with Expo tools are called the managed and bare workflows.

  • 通过托管工作流程,你只需编写 JavaScript/TypeScript,Expo 工具和服务会为你处理其他一切。

    ¥With the managed workflow you only write JavaScript/TypeScript and Expo tools and services take care of everything else for you.

  • 在裸工作流程中,你可以使用任何 Expo 库和服务,并且你负责原生 Android 和 iOS 项目。

    ¥In the bare workflow you can use any Expo library and service, and you are responsible for the native Android and iOS projects.

如果你在没有任何 Expo 工具的情况下使用过 React Native,那么你就使用过 "裸工作流程",但是,这个名字可能听起来并不熟悉。当某件事有名字时,谈论它会更容易,所以我们称之为 "bare" - 有点开玩笑,因为现有术语 "裸机"。如果你可以直接访问原生代码,那么它就是一个裸项目。你可以在裸 React Native 项目中使用任何 Expo 工具和 EAS 服务。

¥If you have used React Native without any Expo tools then you have used the "bare workflow", however, the name probably doesn't sound familiar. It's easier to talk about something when it has a name, so we call this "bare" — somewhat in jest, and because of the existing term "bare metal". If you have direct access to the native code it's a bare project. You can use any Expo tools and EAS services in a bare React Native project.

托管工作流程

¥Managed workflow

托管工作流程有点像 导轨创建反应应用,但针对的是 React Native。

¥The managed workflow is kind of like Rails and Create React App, but for React Native.

开发者在计算机上使用 Expo CLI 并在移动设备上使用开发客户端来构建托管工作流应用(对于更简单的项目,可以使用 Expo Go 应用;当项目不断增长时,可以使用 开发构建)。托管工作流应用通常使用一项或多项 Expo 服务,例如 推送通知buildupdates

¥Developers build managed workflow apps using Expo CLI on their computer and a development client on their mobile devices (either the Expo Go app for more simple projects or a development build when your project grows). Managed workflow apps typically use one or more Expo services, such as push notifications, build, and updates.

Expo 试图尽可能地为你管理构建应用的复杂性,这就是我们将其称为托管工作流程的原因。使用托管工作流程的开发者不经常使用 Android Studio 或 Xcode(尽管它可能对调试有用),他们通过 应用配置 - app.json/app.config.js配置插件 编写 JavaScript 代码并管理配置,例如应用图标和启动屏幕。Expo SDK 公开了一组日益全面的 API,使你能够访问相机、生物识别身份验证、文件系统、触觉等设备功能。开发者还可以利用大多数 React Native 生态系统中可用的库

¥Expo tries to manage as much of the complexity of building apps for you as we can, which is why we call it the managed workflow. A developer using the managed workflow doesn't use Android Studio or Xcode often (although it may be useful for debugging), they write JavaScript code and manage configuration, such as the app icon and splash screen, through app config — app.json/app.config.js or config plugins. The Expo SDK exposes an increasingly comprehensive set of APIs that give you the power to access device capabilities like the camera, biometric authentication, file system, haptics, and so on. Developers can also make use of most libraries available in the React Native ecosystem.

虽然你可以使用托管工作流程做很多事情,但你不能用它做所有事情,那么当你遇到 limitation 时你有什么选择?

¥While you can do a lot with the managed workflow, you can't do everything with it, so what are your options when you encounter a limitation?

如果我遇到限制会怎样?

¥What happens if I run up against a limitation?

如果你需要完全控制应用中的原生代码,则可以生成原生项目并使用裸工作流程继续开发。你可以通过运行 npx expo prebuild 来完成此操作。

¥If you get to the point where you need to have full control over the native code in your app, you can generate the native projects and continue development using the bare workflow. You can do this by running npx expo prebuild.

裸工作流程

¥Bare workflow

在裸工作流程中,开发者拥有完全的控制权,但随之而来的复杂性也随之而来。你可以使用 Expo SDK、开发版本以及所有 Expo 和 EAS 服务 中的所有包。在这种情况下,大多数情况下不支持使用 app.json/app.config.js 进行配置;相反,你需要直接配置每个原生项目。

¥In the bare workflow, the developer has complete control, along with the complexity that comes with that. You can use all packages from the Expo SDK, development builds, and all Expo and EAS Services. Configuration with app.json/app.config.js is mostly not supported in this context; instead, you will need to configure each native project directly.

工作流程比较

¥Workflow comparison

特性托管工作流程裸工作流程
仅使用 JavaScript/TypeScript 开发应用
使用 Expo 构建服务来创建你的 Android 和 iOS 版本(与 EAS 构建)
使用 Expo 的推送通知服务
使用 Expo 的更新功能
接入 Expo SDK
添加自定义原生代码并管理原生依赖
在 Xcode 和 Android Studio 中进行开发
使用 Expo Go 应用进行迭代(如果你关注 这些指导方针

哪种工作流程适合我?

¥Which workflow is right for me?

  • Expo 永远不会将你锁定,你可以随时从托管项目生成原生 Android 和 iOS 项目。你可以在托管项目或裸项目中使用一个或多个库或服务。

    ¥Expo never locks you in, you can generate the native Android and iOS projects from your managed project at any time you like. You can use one library or service or many, in managed or bare projects.

  • 如果你是移动开发新手或者开发新手,一般情况下,我们建议你使用托管工作流程。原生开发工具链带来了巨大的复杂性,而托管工作流允许你仅在必要时处理这种复杂性。

    ¥If you are new to mobile development or new to development, in general, we recommend that you use the managed workflow. There is a huge amount of complexity that comes along with the native development toolchain and the managed workflow allows you to deal with that complexity only when necessary.

  • 如果你更有经验,那么使用托管工作流程启动每个新项目并仅在需要时生成原生项目也没有什么坏处。

    ¥If you are more experienced it also doesn't hurt to start every new project with the managed workflow and only generate the native projects when needed.

总之,由于限制,当你需要时使用裸工作流,否则使用托管工作流,并且你很可能希望从托管工作流开始。

¥In summary, use the bare workflow when you need it due to limitations, otherwise use the managed workflow, and you most likely want to start with the managed workflow.

下一步

¥Next step

如果你想更全面地了解如何使用托管工作流程构建端到端应用,请 你应该按照教程进行操作 并构建通用应用。

¥If you want a more complete picture of building an app end-to-end with the managed workflow, you should follow the tutorial and build a universal app.

Expo 中文网 - 粤ICP备13048890号