expo-updates 55.0.30 → 55.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,13 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 55.0.31 — 2026-09-17
14
+
15
+ ### 🐛 Bug fixes
16
+
17
+ - [iOS] Apply bundle diffs against the embedded bundle in the app binary when the launched update is the embedded one, instead of failing to resolve a patch base and downloading the full bundle. ([#50018](https://github.com/expo/expo/pull/50018) by [@alanjhughes](https://github.com/alanjhughes))
18
+ - [Android] Apply bundle diffs against the embedded bundle in the app binary when the launched update is the embedded one, instead of failing to resolve a patch base and downloading the full bundle. ([#50019](https://github.com/expo/expo/pull/50019) by [@alanjhughes](https://github.com/alanjhughes))
19
+
13
20
  ## 55.0.30 — 2026-08-28
14
21
 
15
22
  ### 🐛 Bug fixes
@@ -42,7 +42,7 @@ expoModule {
42
42
  }
43
43
 
44
44
  group = 'host.exp.exponent'
45
- version = '55.0.30'
45
+ version = '55.0.31'
46
46
 
47
47
  // Utility method to derive boolean values from the environment or from Java properties,
48
48
  // and return them as strings to be used in BuildConfig fields
@@ -89,7 +89,7 @@ android {
89
89
  namespace "expo.modules.updates"
90
90
  defaultConfig {
91
91
  versionCode 31
92
- versionName '55.0.30'
92
+ versionName '55.0.31'
93
93
  consumerProguardFiles("proguard-rules.pro")
94
94
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
95
95
 
@@ -22,6 +22,7 @@ import expo.modules.updates.manifest.ResponsePartHeaderData
22
22
  import expo.modules.updates.manifest.ResponsePartInfo
23
23
  import expo.modules.updates.manifest.UpdateFactory
24
24
  import expo.modules.updates.selectionpolicy.SelectionPolicies
25
+ import expo.modules.updates.utils.AndroidResourceAssetUtils
25
26
  import kotlinx.coroutines.suspendCancellableCoroutine
26
27
  import okhttp3.Cache
27
28
  import okhttp3.Headers
@@ -51,6 +52,7 @@ import kotlin.math.min
51
52
 
52
53
  private const val PATCH_TEMP_SUFFIX = ".patch"
53
54
  private const val PATCHED_TEMP_SUFFIX = ".patched"
55
+ private const val PATCH_BASE_TEMP_SUFFIX = ".base"
54
56
  private const val A_IM_HEADER = "A-IM"
55
57
  private const val IM_HEADER = "im"
56
58
  private const val EXPO_BASE_UPDATE_ID_RESPONSE_HEADER = "expo-base-update-id"
@@ -58,6 +60,8 @@ private const val EXPO_CURRENT_UPDATE_ID_HEADER = "Expo-Current-Update-ID"
58
60
  private const val EXPO_REQUESTED_UPDATE_ID_HEADER = "Expo-Requested-Update-ID"
59
61
  private const val EXPO_EMBEDDED_UPDATE_ID_HEADER = "Expo-Embedded-Update-ID"
60
62
 
63
+ internal typealias EmbeddedAssetExtractor = (AssetEntity, File) -> Unit
64
+
61
65
  /**
62
66
  * Utility class that holds all the logic for downloading data and files, such as update manifests
63
67
  * and assets, using an instance of [OkHttpClient].
@@ -107,7 +111,8 @@ class FileDownloader(
107
111
  progressListener: FileDownloadProgressListener? = null,
108
112
  allowPatch: Boolean,
109
113
  launchedUpdate: UpdateEntity? = null,
110
- requestedUpdate: UpdateEntity? = null
114
+ requestedUpdate: UpdateEntity? = null,
115
+ embeddedAssetExtractor: EmbeddedAssetExtractor? = null
111
116
  ): FileDownloadResult {
112
117
  try {
113
118
  val response = downloadData(request, progressListener)
@@ -176,7 +181,8 @@ class FileDownloader(
176
181
  updatesDirectory = updatesDirectory,
177
182
  launchedUpdate = launchedUpdate,
178
183
  requestedUpdate = requestedUpdate,
179
- expectedBase64URLEncodedSHA256Hash = expectedBase64URLEncodedSHA256Hash
184
+ expectedBase64URLEncodedSHA256Hash = expectedBase64URLEncodedSHA256Hash,
185
+ embeddedAssetExtractor = embeddedAssetExtractor
180
186
  )
181
187
  }.getOrElse {
182
188
  logger.warn(
@@ -294,36 +300,47 @@ class FileDownloader(
294
300
  updatesDirectory: File,
295
301
  launchedUpdate: UpdateEntity,
296
302
  requestedUpdate: UpdateEntity?,
297
- expectedBase64URLEncodedSHA256Hash: String?
303
+ expectedBase64URLEncodedSHA256Hash: String?,
304
+ embeddedAssetExtractor: EmbeddedAssetExtractor? = null
298
305
  ): ByteArray {
299
306
  val launchAssetContext = prepareAssetForDiff(
300
307
  asset = asset,
301
308
  responseBody = responseBody,
309
+ destination = destination,
302
310
  updatesDirectory = updatesDirectory,
303
- launchedUpdate = launchedUpdate
311
+ launchedUpdate = launchedUpdate,
312
+ embeddedAssetExtractor = embeddedAssetExtractor
304
313
  )
305
314
 
306
- return applyHermesDiff(
307
- baseFile = launchAssetContext.baseFile,
308
- diffBody = responseBody,
309
- destination = destination,
310
- expectedBase64URLEncodedSHA256Hash = expectedBase64URLEncodedSHA256Hash,
311
- asset = asset,
312
- requestedUpdateId = requestedUpdate?.id?.toString()
313
- )
315
+ try {
316
+ return applyHermesDiff(
317
+ baseFile = launchAssetContext.baseFile,
318
+ diffBody = responseBody,
319
+ destination = destination,
320
+ expectedBase64URLEncodedSHA256Hash = expectedBase64URLEncodedSHA256Hash,
321
+ asset = asset,
322
+ requestedUpdateId = requestedUpdate?.id?.toString()
323
+ )
324
+ } finally {
325
+ if (launchAssetContext.isTemporary) {
326
+ launchAssetContext.baseFile.delete()
327
+ }
328
+ }
314
329
  }
315
330
 
316
- internal data class LaunchAssetContext(val baseFile: File)
331
+ internal data class LaunchAssetContext(val baseFile: File, val isTemporary: Boolean = false)
317
332
 
318
333
  @VisibleForTesting
319
334
  internal fun prepareAssetForDiff(
320
335
  asset: AssetEntity,
321
336
  responseBody: ResponseBody,
337
+ destination: File,
322
338
  updatesDirectory: File,
323
- launchedUpdate: UpdateEntity
339
+ launchedUpdate: UpdateEntity,
340
+ embeddedAssetExtractor: EmbeddedAssetExtractor? = null
324
341
  ): LaunchAssetContext {
325
342
  return try {
326
- preparePatchBaseAsset(asset, updatesDirectory, launchedUpdate)
343
+ preparePatchBaseAsset(asset, destination, updatesDirectory, launchedUpdate, embeddedAssetExtractor)
327
344
  } catch (e: Exception) {
328
345
  responseBody.close()
329
346
  if (e is IOException) {
@@ -336,8 +353,10 @@ class FileDownloader(
336
353
 
337
354
  private fun preparePatchBaseAsset(
338
355
  asset: AssetEntity,
356
+ destination: File,
339
357
  updatesDirectory: File,
340
- launchedUpdate: UpdateEntity
358
+ launchedUpdate: UpdateEntity,
359
+ embeddedAssetExtractor: EmbeddedAssetExtractor? = null
341
360
  ): LaunchAssetContext {
342
361
  if (!asset.isLaunchAsset) {
343
362
  throw IOException("Received patch for non-launch asset ${asset.key}")
@@ -351,29 +370,60 @@ class FileDownloader(
351
370
  val launchAssetRelativePath = launchAssetEntity.relativePath
352
371
  ?: throw IOException("Launch asset for update $currentUpdateId is missing a relative path")
353
372
 
354
- val baseFile = File(updatesDirectory, launchAssetRelativePath)
373
+ // BSPatch needs a real path, so an asset inside the APK is extracted first.
374
+ val isEmbeddedLaunchAsset = AndroidResourceAssetUtils.isAndroidResourceAsset(launchAssetRelativePath)
375
+ val baseFile = if (isEmbeddedLaunchAsset) {
376
+ extractEmbeddedPatchBaseAsset(launchAssetEntity, destination, embeddedAssetExtractor)
377
+ } else {
378
+ File(updatesDirectory, launchAssetRelativePath)
379
+ }
355
380
  if (!baseFile.exists()) {
356
381
  throw IOException("Base asset $baseFile is missing; cannot apply patch")
357
382
  }
358
383
 
359
- val actualBaseHash = try {
360
- UpdatesUtils.toBase64Url(UpdatesUtils.sha256(baseFile))
361
- } catch (_: Exception) {
362
- null
384
+ val expectedBaseHash = launchAssetEntity.expectedHash
385
+ if (expectedBaseHash != null) {
386
+ val actualBaseHash = try {
387
+ UpdatesUtils.toBase64Url(UpdatesUtils.sha256(baseFile))
388
+ } catch (_: Exception) {
389
+ null
390
+ }
391
+ if (actualBaseHash != null && expectedBaseHash != actualBaseHash) {
392
+ logger.warn(
393
+ "Asset hash mismatch for update $currentUpdateId; expected=$expectedBaseHash actual=$actualBaseHash",
394
+ UpdatesErrorCode.AssetsFailedToLoad,
395
+ currentUpdateId.toString(),
396
+ asset.key
397
+ )
398
+ if (isEmbeddedLaunchAsset) {
399
+ baseFile.delete()
400
+ }
401
+ throw IOException("Asset hash mismatch for update $currentUpdateId; expected=$expectedBaseHash actual=$actualBaseHash")
402
+ }
363
403
  }
364
404
 
365
- val expectedBaseHash = launchAssetEntity.expectedHash
366
- if (expectedBaseHash != null && actualBaseHash != null && expectedBaseHash != actualBaseHash) {
367
- logger.warn(
368
- "Asset hash mismatch for update $currentUpdateId; expected=$expectedBaseHash actual=$actualBaseHash",
369
- UpdatesErrorCode.AssetsFailedToLoad,
370
- currentUpdateId.toString(),
371
- asset.key
372
- )
373
- throw IOException("Asset hash mismatch for update $currentUpdateId; expected=$expectedBaseHash actual=$actualBaseHash")
405
+ return LaunchAssetContext(baseFile, isTemporary = isEmbeddedLaunchAsset)
406
+ }
407
+
408
+ @Throws(IOException::class)
409
+ private fun extractEmbeddedPatchBaseAsset(
410
+ launchAssetEntity: AssetEntity,
411
+ destination: File,
412
+ embeddedAssetExtractor: EmbeddedAssetExtractor?
413
+ ): File {
414
+ if (embeddedAssetExtractor == null) {
415
+ throw IOException("The launch asset lives in the app binary and cannot be extracted without an extractor")
374
416
  }
375
417
 
376
- return LaunchAssetContext(baseFile)
418
+ val baseFile = File(destination.absolutePath + PATCH_BASE_TEMP_SUFFIX)
419
+ try {
420
+ baseFile.parentFile?.mkdirs()
421
+ embeddedAssetExtractor(launchAssetEntity, baseFile)
422
+ } catch (e: Exception) {
423
+ baseFile.delete()
424
+ throw e as? IOException ?: IOException("Failed to extract the embedded launch asset", e)
425
+ }
426
+ return baseFile
377
427
  }
378
428
 
379
429
  @VisibleForTesting
@@ -678,7 +728,8 @@ class FileDownloader(
678
728
  extraHeaders: JSONObject,
679
729
  launchedUpdate: UpdateEntity?,
680
730
  requestedUpdate: UpdateEntity?,
681
- assetLoadProgressListener: ((Double) -> Unit)? = null
731
+ assetLoadProgressListener: ((Double) -> Unit)? = null,
732
+ embeddedAssetExtractor: EmbeddedAssetExtractor? = null
682
733
  ): AssetDownloadResult {
683
734
  if (asset.url == null) {
684
735
  val message = "Failed to download asset ${asset.key}"
@@ -722,7 +773,8 @@ class FileDownloader(
722
773
  assetLoadProgressListener?.let { listener -> { listener.invoke(it) } },
723
774
  allowPatch = canApplyPatch,
724
775
  launchedUpdate = launchedUpdate,
725
- requestedUpdate = requestedUpdate
776
+ requestedUpdate = requestedUpdate,
777
+ embeddedAssetExtractor = embeddedAssetExtractor
726
778
  )
727
779
 
728
780
  asset.downloadTime = Date()
@@ -14,6 +14,7 @@ import kotlinx.coroutines.CoroutineScope
14
14
  import kotlinx.coroutines.Dispatchers
15
15
  import kotlinx.coroutines.SupervisorJob
16
16
  import java.io.File
17
+ import java.io.IOException
17
18
 
18
19
  data class ProcessSuccessLoaderResult(
19
20
  val availableUpdate: UpdateEntity?,
@@ -66,9 +67,28 @@ class RemoteLoader internal constructor(
66
67
  embeddedUpdate: UpdateEntity?
67
68
  ): FileDownloader.AssetDownloadResult {
68
69
  val extraHeaders = FileDownloader.getExtraHeadersForRemoteAssetRequest(launchedUpdate, embeddedUpdate, requestedUpdate)
69
- return mFileDownloader.downloadAsset(assetEntity, updatesDirectory, extraHeaders, launchedUpdate, requestedUpdate) { progress ->
70
- assetLoadProgressListener(assetEntity, progress)
71
- }
70
+ return mFileDownloader.downloadAsset(
71
+ asset = assetEntity,
72
+ destinationDirectory = updatesDirectory,
73
+ extraHeaders = extraHeaders,
74
+ launchedUpdate = launchedUpdate,
75
+ requestedUpdate = requestedUpdate,
76
+ embeddedAssetExtractor = { launchAsset, destination ->
77
+ // The stored path is not the APK asset name; resolve it through the embedded manifest by key.
78
+ val embeddedLaunchAsset = loaderFiles.readEmbeddedUpdate(context, configuration)
79
+ ?.assetEntityList
80
+ ?.find { it.key == launchAsset.key }
81
+ ?: throw IOException("No embedded asset matches launch asset ${launchAsset.key}")
82
+ val assetName = embeddedLaunchAsset.embeddedAssetFilename
83
+ ?: throw IOException("Embedded launch asset ${launchAsset.key} has no APK asset filename")
84
+ context.assets.open(assetName).use { input ->
85
+ destination.outputStream().use { output -> input.copyTo(output) }
86
+ }
87
+ },
88
+ assetLoadProgressListener = { progress ->
89
+ assetLoadProgressListener(assetEntity, progress)
90
+ }
91
+ )
72
92
  }
73
93
 
74
94
  companion object {
@@ -84,6 +84,12 @@ public final class FileDownloader {
84
84
  private let updatesDirectory: URL
85
85
  private let database: UpdatesDatabase
86
86
 
87
+ /// Overridable for testing, where the fixture is not in `updatesBundle`.
88
+ internal var embeddedLaunchAssetUrl: URL? = updatesBundle.url(
89
+ forResource: EmbeddedAppLoader.EXUpdatesBareEmbeddedBundleFilename,
90
+ withExtension: EmbeddedAppLoader.EXUpdatesBareEmbeddedBundleFileType
91
+ )
92
+
87
93
  public convenience init(
88
94
  config: UpdatesConfig,
89
95
  logger: UpdatesLogger,
@@ -557,8 +563,7 @@ public final class FileDownloader {
557
563
  throw DiffError.assetNotLaunch
558
564
  }
559
565
 
560
- let baseAsset = try resolveLaunchAsset(launchedUpdate: launchedUpdate)
561
- let baseFileUrl = try loadAndVerifyAsset(baseAsset)
566
+ let baseFileUrl = try resolveBaseFileUrl(launchedUpdate: launchedUpdate)
562
567
  let requestedUpdateId = requestedUpdate?.updateId.uuidString
563
568
 
564
569
  return try createPatchedAsset(
@@ -571,6 +576,19 @@ public final class FileDownloader {
571
576
  )
572
577
  }
573
578
 
579
+ private func resolveBaseFileUrl(launchedUpdate: Update) throws -> URL {
580
+ if launchedUpdate.status == UpdateStatus.StatusEmbedded {
581
+ // StatusEmbedded only launches for this binary's embedded update.
582
+ guard let embeddedLaunchAssetUrl else {
583
+ throw DiffError.embeddedBaseAssetMissing
584
+ }
585
+ return embeddedLaunchAssetUrl
586
+ }
587
+
588
+ let baseAsset = try resolveLaunchAsset(launchedUpdate: launchedUpdate)
589
+ return try loadAndVerifyAsset(baseAsset)
590
+ }
591
+
574
592
  private func resolveLaunchAsset(launchedUpdate: Update) throws -> UpdateAsset {
575
593
  let currentUpdateId = launchedUpdate.updateId
576
594
  var launchAsset: UpdateAsset?
@@ -1238,6 +1256,7 @@ extension FileDownloader {
1238
1256
  case missingHeader(String)
1239
1257
  case invalidHeader(String)
1240
1258
  case launchAssetNotFound
1259
+ case embeddedBaseAssetMissing
1241
1260
  case baseAssetMissing(path: String)
1242
1261
  case failedToReadBaseAsset(cause: Error)
1243
1262
  case failedToWritePatch(cause: Error, path: String)
@@ -1265,6 +1284,8 @@ extension FileDownloader.DiffError: CustomStringConvertible {
1265
1284
  return "Invalid \(header) header"
1266
1285
  case .launchAssetNotFound:
1267
1286
  return "Launch asset not found for current update"
1287
+ case .embeddedBaseAssetMissing:
1288
+ return "Embedded bundle not found in the app binary"
1268
1289
  case let .baseAssetMissing(path):
1269
1290
  return "Base asset is missing at path \(path)"
1270
1291
  case let .failedToReadBaseAsset(cause):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-updates",
3
- "version": "55.0.30",
3
+ "version": "55.0.31",
4
4
  "description": "Fetches and manages remotely-hosted assets and updates to your app's JS bundle.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -71,5 +71,5 @@
71
71
  "react": "*",
72
72
  "react-native": "*"
73
73
  },
74
- "gitHead": "a7b74adf4f2d7ce2753db963616740ceec558a5f"
74
+ "gitHead": "167ec74a43d77e1b61f751440334f9e645f8d2be"
75
75
  }