工具、工作流程和扩展
详细了解使用开发版本时可用的不同工具、工作流程和扩展。
开发版允许你快速迭代。但你可以扩展开发版的功能,以在团队协作时提供更好的开发体验,或根据需要自定义构建。
🌐 Development builds allow you to iterate quickly. However, you can extend the capabilities of your development build to provide a better developer experience when working in teams or customize the build to suit your needs.
工具
🌐 Tools
通道 URL
🌐 Tunnel URLs
有时,受限的网络条件会使连接开发服务器变得困难。npx expo start 命令可以将你的开发服务器暴露在一个公共可用的 URL 上,从而可以从全球各地通过防火墙访问。如果你无法通过默认的本地局域网选项连接到开发服务器,或者希望在开发过程中获取关于你的实现的反馈,这个选项会很有帮助。
🌐 Sometimes, restrictive network conditions make it difficult to connect to the development server. The npx expo start command exposes your development server on a publicly available URL that is accessible through firewalls from around the globe. This option is helpful if you are not able to connect to your development server with the default LAN option or if you want to get feedback on your implementation while you are developing.
要获取隧道 URL,请在命令行中将 --tunnel 标志 传递给 npx expo start。
🌐 To get a tunneled URL, pass the --tunnel flag to npx expo start from the command line.
已发布的更新
🌐 Published updates
EAS CLI 的 eas update 命令将当前的 JavaScript 和资源文件状态打包成优化的“更新”。该更新由 Expo 存储在托管服务上。应用的开发构建可以加载已发布的更新,而无需检出特定的提交或保持开发机器运行。
🌐 EAS CLI's eas update command bundles the current state of your JavaScript and asset files into an optimized "update". This update is stored on a hosting service by Expo. A development build of your app can load published updates without needing to check out a particular commit or leave a development machine running.
手动输入更新的 URL
🌐 Manually entering an update's URL
当开发版本启动时,它会显示用于加载开发服务器的界面,或者“手动输入 URL”。你可以手动提供一个 URL 来启动特定的分支。URL 的格式如下:
🌐 When a development build launches, it will expose UI to load a development server, or to "Enter URL manually". You can provide a URL manually that will launch a specific branch. The URL follows this pattern:
https://u.expo.dev/[your-project-id]?channel-name=[channel-name] # Example https://u.expo.dev/F767ADF57-B487-4D8F-9522-85549C39F43F?channel-name=main
要获取你项目的 ID,请使用 应用配置的 expo.updates.url 字段中的 URL。要查看通道列表,请运行 eas channel:list。
🌐 To get your project's ID, use the URL in the app config's expo.updates.url field. To see a list of channels, run eas channel:list.
/* TODO: @aman 将此部分移出此页面——将其作为主路径的一部分或独立指南,这是重要部分,应该可以搜索,例如:开发版本/EAS 构建的深度链接 URL(使用 expo-dev-client 时) */
深层链接到更新的 URL
🌐 Deep linking to an update's URL
你可以通过打开格式为 {scheme}://expo-development-client/?url={manifestUrl} 的 URL,将你的应用加载到拥有兼容自定义客户端版本的设备上。你需要传递以下参数:
🌐 You can load your app on a device that has a compatible build of your custom client by opening a URL of the form {scheme}://expo-development-client/?url={manifestUrl}. You'll need to pass the following parameters:
| 参数 | 值 |
|---|---|
scheme | 你客户端的 URL 方案(默认为 exp+{slug},其中 slug 是在应用配置中设置的值) |
manifestUrl | 要加载的更新清单的 URL 编码地址。该 URL 将是 https://u.expo.dev/[your-project-id]?channel-name=[channel-name] |
示例:
🌐 Example:
exp+app-slug://expo-development-client/?url=https%3A%2F%2Fu.expo.dev%2F767ADF57-B487-4D8F-9522-85549C39F43F%2F%3Fchannel-name%3Dmain
在上面的例子中,scheme 是 exp+app-slug,而 manifestUrl 是一个 ID 为 F767ADF57-B487-4D8F-9522-85549C39F43F、通道为 main 的项目。
🌐 In the example above, the scheme is exp+app-slug, and the manifestUrl is a project with an ID of F767ADF57-B487-4D8F-9522-85549C39F43F and a channel of main.
在自动化场景中使用更新深层链接
🌐 Using updates deep links in automation scenarios
在使用自动化(例如在 CI/CD 工作流中)在模拟器或模拟器上启动开发版更新 URL 时,你可以在 URL 中添加 disableOnboarding=1 查询参数,以跳过安装后开发版首次启动时出现的引导屏幕。
🌐 When launching an update URL in a development build on an emulator or simulator using automation, such as in a CI/CD workflow, you can add the disableOnboarding=1 query parameter to the URL to skip the onboarding screen that appears on the first launch of a development build after installation.
应用特定的深层链接
🌐 App-specific deep links
在测试开发版本中的深度链接时,例如在 Expo Router 应用中导航到特定屏幕或测试在 Oauth 登录流程中重定向回应用时,应像深度链接到应用的独立版本(例如 myscheme://path/to/screen)一样准确构建 URL。
🌐 When testing deep links in your development build, such as when navigating to a specific screen in an Expo Router app or testing redirecting back to your app during an Oauth login flow, construct the URL exactly as you would if you were deep-linking into a standalone build of your app (for example, myscheme://path/to/screen).
你的项目必须已经在开发版本中打开,应用专用深度链接才能正常工作。目前不支持通过应用专用深度链接冷启动开发版本。避免在应用专用深度链接的路径中使用 expo-development-client,因为它是用于启动更新 URL 的保留路径。
🌐 Your project must be already open in the development build for an app-specific deep link to work. Cold-launching a development build with an app-specific deep link is not currently supported. Avoid using expo-development-client in your app-specific deep links in the path, as it is a reserved path used for launching an updated URL.
二维码
🌐 QR codes
你可以使用我们的端点生成可以通过开发版本轻松加载的二维码。
🌐 You can use our endpoint to generate a QR code that can be easily loaded by a development build.
当向 https://qr.expo.dev/development-client 发送请求并提供像 appScheme 和 url 这样的查询参数时,将会收到一个响应,其中包含一个 SVG 图片的二维码,可以轻松扫描以加载你的项目开发版本。
🌐 Requests send to https://qr.expo.dev/development-client when supplied the query parameters such as appScheme and url will receive a response with an SVG image containing a QR code that can be easily scanned to load a version of your project in your development build.
| 参数 | 值 |
|---|---|
appScheme | 开发版本的 URL 编码深度链接方案(默认为 exp+{slug},其中 slug 是在应用配置中设置的值) |
url | 要加载的更新清单的 URL 编码 URL。该 URL 将是 https://u.expo.dev/[your-project-id]?channel-name=[channel-name] |
示例:
🌐 Example:
https://qr.expo.dev/development-client?appScheme=exp%2Bapps-slug&url=https%3A%2F%2Fu.expo.dev%2FF767ADF57-B487-4D8F-9522-85549C39F43F0%3Fchannel-name%3Dmain
在上面的例子中,scheme 是 exp+app-slug,而 url 是一个 ID 为 F767ADF57-B487-4D8F-9522-85549C39F43F、通道为 main 的项目。
🌐 In the example above, the scheme is exp+app-slug, and the url is a project with an ID of F767ADF57-B487-4D8F-9522-85549C39F43F and a channel of main.
工作流程示例
🌐 Example workflows
以下是一些工作流程示例,旨在帮助你的团队充分利用开发版本。如果你想出了其他对其他团队有用的工作流程,提交一个 PR 与大家分享你的知识!
🌐 These are a few examples of workflows to help your team get the most out of your development build. If you come up with others that would be useful for other teams, submit a PR to share your knowledge!
PR 预览
🌐 PR previews
你可以将 CI 流程设置为在拉取请求更新时发布 EAS 更新,并添加用于查看兼容开发版本中的更改的 QR 代码。
🌐 You can set up your CI process to publish an EAS Update whenever a pull request is updated and add a QR code that is used to view the change in a compatible development build.
查看 在拉取请求上发布应用预览的说明,了解如何在项目中使用 GitHub Actions 实现此工作流程,或将其作为你选择的持续集成模板。
🌐 See instructions for publishing app previews on pull requests to implement this workflow in your project using GitHub Actions or serve as a template in your CI of choice.
扩展
🌐 Extensions
扩展允许你使用附加功能来扩展你的开发客户端。
🌐 Extensions allow you to extend your development client with additional capabilities.
扩展开发菜单
🌐 Extending the dev menu
可以使用 registerDevMenuItems API 扩展开发者菜单,以包含额外的按钮:
🌐 The dev menu can be extended to include extra buttons by using the registerDevMenuItems API:
import { registerDevMenuItems } from 'expo-dev-menu'; const devMenuItems = [ { name: 'My Custom Button', callback: () => console.log('Hello world!'), }, ]; registerDevMenuItems(devMenuItems);
这将在开发菜单中创建一个新部分,其中包含你已注册的按钮:
🌐 This will create a new section in the dev menu that includes the buttons you have registered:
registerDevMenuItems的后续调用将覆盖所有之前的条目。
EAS 更新
🌐 EAS Update
EAS 更新扩展提供了在开发客户端中查看和加载已发布更新的功能。
🌐 The EAS Update extension provides the ability to view and load published updates in your development client.
它适用于所有开发客户端 v0.9.0 及以上版本。要安装它,你需要最新版本的 expo-updates 发布:
🌐 It's available for all development clients v0.9.0 and above. To install it, you'll need the most recent publish of expo-updates:
- npx expo install expo-dev-client expo-updates配置 EAS 更新
🌐 Configure EAS Update
如果你尚未在项目中配置 EAS 更新,可以在这里找到关于如何操作的详细说明。
🌐 If you have not yet configured EAS Updates in your project, you can find additional instructions on how to do so here.
你现在可以通过 Extensions 面板在开发版本中查看和加载 EAS 更新。
🌐 You can now view and load EAS Updates in your development build via the Extensions panel.
在应用配置中设置运行时版本
🌐 Set runtimeVersion in app config
当你创建项目的开发构建时,你将获得一个稳定的环境来加载由 JavaScript 或其他资源相关更改定义的应用更新。其他对应用的更改,无论是直接在 android 和 ios 目录中定义,还是通过你选择安装的包或 SDK 定义,都需要你创建一个新的开发构建版本。
🌐 When you create a development build of your project, you'll get a stable environment to load any changes to your app that are defined in JavaScript or other asset-related changes. Other changes to your app, whether defined directly in android and ios directories or by packages or SDKs you choose to install, will require you to create a new build of your development build.
为了在应用的 JavaScript 层和原生层之间强制执行 API 合约,你应该在应用配置中设置 runtimeVersion 值。每次构建都会将此值嵌入,并且只会加载具有相同 runtimeVersion 的包,无论是在开发环境还是生产环境中。
🌐 To enforce an API contract between the JavaScript and native layers of your app, you should set the runtimeVersion value in the app config. Each build you make will have this value embedded and will only load bundles with the same runtimeVersion, in both development and production.