重打包应用

在不进行完整本地重建的情况下,用更新的 JavaScript 包重打包现有的 APK、IPA 或 .app。


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

@expo/repack-app 是一个 CLI 工具,可以重新打包已存在的 Android APK、iOS IPA 或 iOS .app 包,而无需进行完整的原生构建。它会使用新的 JavaScript (JS) 包、资源和应用元数据(例如应用名称、版本以及包名或 bundle 标识符)更新现有的构件。由于不涉及原生编译,重新打包通常比完整的原生构建要快得多。

要了解更多关于指纹和重新打包如何协同工作以加速 CI 的信息,请参阅博客文章 在 EAS 工作流中使用指纹和重新打包加速持续集成

🌐 To learn more about how fingerprint and repack work together to accelerate CI, see Accelerating Continuous Integration with Fingerprint and Repack in EAS Workflows blog post.

Prerequisites

2 requirements

1.

现有的构建产物

从你的 Expo 项目生成的构建产物:用于 Android 的 APK,或用于 iOS 的 IPA 或 .app 包。

2.

签名凭证(可选)

如果重新打包的产物需要能够在设备上安装,则为必需。更多信息,请参阅 签名

何时使用重新打包

🌐 When to use repack

Repack 假设源二进制文件的原生部分自构建以来未发生变化。如果你添加了原生依赖、更改了 config 插件 或升级了 Expo SDK,重新打包的产物将包含期望但不存在的原生 API 的 JS,可能会在运行时崩溃。使用 fingerprint 来比较源二进制文件的原生身份与当前项目。如果指纹匹配,则重新打包是安全的。如果不同,则应进行完整的原生构建。

🌐 Repack assumes the source binary's native side is unchanged since it was built. If you added a native dependency, changed a config plugin, or upgraded the Expo SDK, a repacked artifact will have JS that expects native APIs that do not exist, and will likely crash at runtime. Use fingerprint to compare the source binary's native identity against your current project. If the fingerprints match, then repack is safe. If they differ, do a full native build instead.

Repack 不是 EAS Update 的替代方案。EAS Update 会将新的 JS 包发送到已经安装的应用中,用户会在下次启动时看到它。Repack 会生成一个新的可安装构件。一个好的经验法则是将 repack 用于内部测试(QA 设备、测试人员、CI 冒烟测试),并使用 EAS Update 将 JS 更改交付给生产用户。

🌐 Repack is not a replacement for EAS Update. EAS Update ships a new JS bundle to apps that are already installed, and users see it on the next launch. Repack produces a new installable artifact. A good rule of thumb is to use repack for internal testing (QA devices, testers, CI smoke tests) and use EAS Update to deliver JS changes to production users.

用例

🌐 Use cases

  • QA周期:将一个基础版本分发给测试人员,然后在每次迭代中重新打包带有JS修复的版本,而无需等待原生重建。
  • CI 优化:每个指纹只构建一次本地版本,然后在每个后续 PR 中重新打包 JS 包,将等待时间从几分钟缩短到几秒钟。
  • 分支测试:针对相同的本地二进制文件测试多个 JS 分支,以隔离仅 JavaScript 的更改。

用法

🌐 Usage

独立命令行接口

🌐 Standalone CLI

你需要从你项目的根目录运行下方为 Android 和 iOS 平台指定的命令。至少,需要 --platform--source-app。该工具在底层运行 npx expo export:embed 来生成一个新的 JS 打包包,将其替换到源二进制文件中,并写入输出产物。

🌐 You need to run the commands specified for Android and iOS platforms below from your project's root directory. At minimum, --platform and --source-app are required. The tool runs npx expo export:embed under the hood to produce a fresh JS bundle, swaps it into the source binary, and writes the output artifact.

输出格式总是与 --source-app 输入相匹配。APK 输入生成 APK,IPA 输入生成 IPA,而 .app 包输入生成 .app 包。

🌐 The output format always matches the --source-app input. An APK input produces an APK, an IPA produces an IPA, and a .app bundle produces a .app bundle.

Terminal
npx @expo/repack-app --platform android --source-app MyApp.apk

使用国际音标(IPA):

🌐 Using an IPA:

Terminal
npx @expo/repack-app --platform ios --source-app MyApp.ipa

使用 .app 打包包(对于模拟器构建,iOS 设备的工件总是 IPA 文件):

🌐 Using a .app bundle (for simulator builds, the iOS device artifacts are always IPAs):

Terminal
npx @expo/repack-app --platform ios --source-app MyApp.app

EAS 工作流程

🌐 EAS Workflows

EAS Workflows 提供了一个预打包的 repack 作业类型,可以自动处理签名和构建管理。完整的语法、参数和示例请参见 EAS Workflows 预打包作业

🌐 EAS Workflows provides a pre-packaged repack job type that handles signing and build management automatically. See EAS Workflows pre-packaged jobs for full syntax, parameters, and examples.

签名

🌐 Signing

要生成可在物理设备上安装的工件,请在传递 --platform--source-app 的同时提供签名凭证。没有这些凭证,Android APK 将输出为未签名,iOS IPA 无法安装到设备上。面向模拟器的 iOS .app 包不需要签名,可以跳过此步骤。

🌐 To produce an artifact installable on a physical device, pass signing credentials alongside --platform and --source-app. Without them, the Android APK is output unsigned and the iOS IPA cannot be installed on a device. iOS .app bundles intended for the simulator do not need signing and can skip this step.

如果你本地尚未拥有签名凭据,请参阅 App credentials 了解如何获取密钥库(Android)或签名身份和配置描述文件(iOS)。

🌐 If you do not already have signing credentials locally, see App credentials for how to obtain a keystore (Android) or a signing identity and provisioning profile (iOS).

Terminal
npx @expo/repack-app --platform android --source-app MyApp.apk --ks keystore.jks --ks-key-alias my-alias

请参阅 Android 特定选项 以获取密钥库密码标志和其他设置。

🌐 See the Android-specific options for keystore password flags and other settings.

传递签名身份和配置描述文件:

🌐 Pass a signing identity and provisioning profile:

注意:iOS 重新打包仅支持临时分发和开发签名。

Terminal
npx @expo/repack-app --platform ios --source-app MyApp.ipa --signing-identity "Apple Distribution: ..." --provisioning-profile /path/to/profile.mobileprovision

查看iOS 特定选项以获取完整的签名标志列表。

🌐 See the iOS-specific options for the full list of signing flags.

--js-bundle-only 模式

🌐 --js-bundle-only mode

默认情况下,repack 会更新 JS 包、资源和应用元数据(应用名称、版本、包标识符以及 expo-updates 清单)。当你只想更新 JS 包而保持所有原生配置不变时,请传入 --js-bundle-only

🌐 By default, repack updates the JS bundle, assets, and app metadata (app name, version, bundle identifier, and the expo-updates manifest). Pass --js-bundle-only when you intentionally want to update only the JS bundle and leave all native config untouched.

Terminal
npx @expo/repack-app --platform android --source-app MyApp.apk --js-bundle-only

局限性

🌐 Limitations

不推荐将重新打包用于生产环境的 Google Play 商店或 Apple App Store 提交。生产版本应通过完整的构建流程,以确保正确的符号化和签名。

🌐 Repack is not recommended for production Google Play Store or Apple App Store submissions. Production builds should go through the complete build pipeline for correct symbolication and signing.

命令行接口参考

🌐 CLI reference

Usage: @expo/repack-app [options] [project-root]

参数

🌐 Arguments

参数描述
[project-root]项目根目录的路径。默认是当前工作目录。

选项

🌐 Options

选项描述
-p, --platform <platform>必填。 用于重新打包应用的平台(androidios)。
--source-app <path>必填。 源应用路径(Android 为 APK,iOS 为 IPA 或 .app)。输出格式与输入格式相同。
-o, --output <path>输出工件的路径。默认为项目根目录下的 repacked.apkrepacked.iparepacked.app,与源格式匹配。
-w, --working-directory <path>临时文件工作目录的路径。
--skip-working-dir-cleanup在重新打包完成后跳过清理工作目录。对调试很有用。
-v, --verbose启用详细日志记录。
--js-bundle-only仅更新 JS 包,并跳过原生配置更新(例如应用名称、版本及其他元数据)。
--embed-bundle-assets强制运行 npx expo export:embed 以生成 JS 包和资源,即使是在通常从开发服务器加载包的调试构建中也如此。
--bundle-assets-sourcemap-output <path>在指定路径生成源映射。需要 --embed-bundle-assets

安卓特定选项

🌐 Android-specific options

选项描述
--ks <path>密钥库文件的路径。
--ks-pass <password>密钥库密码。默认值为 pass:android。支持的格式:pass:<password>env:<name>file:<file>
--ks-key-alias <alias>密钥库密钥别名。
--ks-key-pass <password>密钥库密钥密码。支持的格式:pass:<password>env:<name>file:<file>
--android-build-tools-dir <path>Android SDK 构建工具目录的路径。

iOS 特定选项

🌐 iOS-specific options

选项描述
--signing-identity <identity>代码签名身份。
--provisioning-profile <path>配置描述文件的路径。或者,多目标应用的 JSON 编码值(例如,在打包应用扩展时)。