预构建的 Expo 模块

了解预构建的 Expo 模块如何减少 Android 和 iOS 上的原生构建时间。


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

本地构建时间可能会降低你的开发工作流程效率。Expo 提供其最复杂模块的预构建版本,因此你的项目会链接预编译的二进制文件,而不是在每次构建时从源代码重新编译它们。在 Android 上,这些二进制文件以 .aar 文件的形式通过 Gradle 链接;在 iOS 上,它们以通过 CocoaPods 链接的 XCFrameworks 形式提供。两者都打包在常规的 Expo npm 包中,而尚未预编译的包会自动回退为从源代码构建——预编译模块和源代码构建模块可以在同一个项目中共存。

🌐 Native build times can slow down your development workflow. Expo provides prebuilt versions of its most complex modules so your project links pre-compiled binaries instead of recompiling them from source on every build. On Android, those binaries ship as .aar files linked through Gradle; on iOS, they ship as XCFrameworks linked through CocoaPods. Both are bundled into the regular Expo npm packages, and packages that aren't yet precompiled fall back to building from source automatically — precompiled and source-built modules coexist in the same project.

大多数项目不需要做任何事情——在使用受支持的 SDK 版本的新项目和现有项目中,预构建的 Expo 模块会自动启用。

  • Android:自 SDK 53 起默认启用。
  • iOS:在 SDK 56 及以上版本中默认启用。在 SDK 55 中,仅在 EAS Build 上默认启用——在本地构建中选择加入,请在你的 shell 中设置 EXPO_USE_PRECOMPILED_MODULES=1
在 iOS 上禁用

EXPO_USE_PRECOMPILED_MODULES 设置为 0。对于本地构建,在你的 shell 中导出环境变量。

🌐 Set EXPO_USE_PRECOMPILED_MODULES to 0. For local builds, export the env var in your shell.

对于 EAS Build,请创建一个 EAS 环境变量

🌐 For EAS Build, create an EAS environment variable:

Terminal
eas env:create --name EXPO_USE_PRECOMPILED_MODULES --value 0 --visibility plaintext

CLI 会提示你选择该变量适用于哪些环境(developmentpreviewproduction)。

🌐 The CLI will prompt you to select which environment(s) (development, preview, production) the variable applies to.

通过 Expo 自动链接禁用特定模块

package.json 中使用 buildFromSource 配置 Expo 自动链接。使用 ".*" 可以选择退出所有预构建模块,或列出特定的包名称。相同的设置也适用于 androidios

🌐 Configure Expo Autolinking with buildFromSource in package.json. Use ".*" to opt out of every prebuilt module, or list specific package names. The same setting is available for both android and ios:

package.json
{ "name": "your-app-name", "expo": { "autolinking": { "android": { "buildFromSource": [".*"] }, "ios": { "buildFromSource": [".*"] } } } }

通常只有在你自己修改模块源代码时才需要这样做。

🌐 This is typically only needed when you're modifying module source code yourself.