Commit 767841c
fix(android): content-based (CRC32) resource matching for AAB installs + openRawResource density fix (#577)
* fix(android): match copied resources by content (CRC32) for AAB installs
A from-package (PATCH_FROM_APK) hot update copies unchanged resources out
of the on-device package using the path recorded in __diff.json `copies`.
When the baseline uploaded to the server was an APK but the app is
installed from an AAB (Play split APKs), res/ drawable paths are shortened
on device, so the recorded path (e.g. res/drawable-xhdpi-v4/x.webp) does
not exist verbatim and images (webp) silently fall through and go missing.
Add a CRC32 content-match tier in BundledResourceCopier: build a
crc32 -> entry index while scanning the base + split APKs, and when a
`from` path is not found by exact/normalized path, locate the file by the
content checksum supplied via the new manifest `copiesCrc` map. CRC32 is
over the uncompressed content, so it is stable across APK/AAB packaging.
This tier runs before resolveBundledResource (content match is more
reliable than the resource-id heuristic).
Also fix openResolvedResourceStream: use openRawResource(id, typedValue)
with the density-resolved TypedValue instead of openRawResource(id), which
ignored the requested density and could copy the wrong variant.
Backward/forward compatible: manifests without `copiesCrc` (older CLI)
simply skip the CRC tier and fall back to today's path-based behavior.
Requires CLI support: reactnativecn/react-native-update-cli#54
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(android): address review — exact CRC archive + real density-correct copy
Two follow-ups from review on the resource copier:
1. CRC index stored only the entry name, so resolving it back through
availableEntries could yield a different-content entry when two APKs
(base + split) expose the same name with different bytes. Store the
matched ZipEntry together with its SafeZipFile (ZipSource) and copy from
that archive directly.
2. openRawResource(id, typedValue) is a no-op for density: AOSP's
ResourcesImpl re-runs getValue(id, value, true) and overwrites the passed
TypedValue at the current configuration before opening the stream. Instead
of going through openRawResource (or the hidden openNonAsset API), take the
density-correct file path resolved by getValueForDensity and copy that
exact entry from the already-open archives — public API, correct variant.
openRawResource(id) remains only as a defensive fallback.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent edc40be commit 767841c
2 files changed
Lines changed: 75 additions & 5 deletions
File tree
- android/src/main/java/cn/reactnative/modules/update
Lines changed: 58 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
36 | 49 | | |
37 | 50 | | |
38 | 51 | | |
39 | 52 | | |
40 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
41 | 57 | | |
42 | 58 | | |
43 | 59 | | |
44 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
45 | 66 | | |
46 | 67 | | |
47 | 68 | | |
| |||
55 | 76 | | |
56 | 77 | | |
57 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
58 | 83 | | |
59 | 84 | | |
60 | 85 | | |
| |||
76 | 101 | | |
77 | 102 | | |
78 | 103 | | |
| 104 | + | |
79 | 105 | | |
80 | 106 | | |
81 | 107 | | |
| |||
87 | 113 | | |
88 | 114 | | |
89 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
90 | 131 | | |
91 | 132 | | |
92 | 133 | | |
93 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
94 | 145 | | |
95 | 146 | | |
96 | 147 | | |
| |||
104 | 155 | | |
105 | 156 | | |
106 | 157 | | |
107 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
108 | 161 | | |
109 | 162 | | |
110 | 163 | | |
| |||
247 | 300 | | |
248 | 301 | | |
249 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
250 | 306 | | |
251 | 307 | | |
252 | 308 | | |
| |||
Lines changed: 17 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
140 | 145 | | |
141 | 146 | | |
142 | 147 | | |
143 | | - | |
| 148 | + | |
| 149 | + | |
144 | 150 | | |
| 151 | + | |
| 152 | + | |
145 | 153 | | |
146 | 154 | | |
147 | 155 | | |
| |||
153 | 161 | | |
154 | 162 | | |
155 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
156 | 169 | | |
157 | 170 | | |
158 | 171 | | |
| |||
220 | 233 | | |
221 | 234 | | |
222 | 235 | | |
223 | | - | |
| 236 | + | |
| 237 | + | |
224 | 238 | | |
225 | 239 | | |
226 | 240 | | |
| |||
285 | 299 | | |
286 | 300 | | |
287 | 301 | | |
288 | | - | |
| 302 | + | |
289 | 303 | | |
290 | 304 | | |
291 | 305 | | |
| |||
0 commit comments