@oxy.so/app-preset 6.0.0 → 6.1.0

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/README.md CHANGED
@@ -14,7 +14,7 @@ and JSON.
14
14
 
15
15
  | Piece | Import | Replaces |
16
16
  | --- | --- | --- |
17
- | Config plugin | `['@oxy.so/app-preset', {}]` | iOS keychain entitlement + `expo-build-properties` + `@oxy.so/services/plugins/withOxySharedPermissions` (which signs every release with the ecosystem key, see below) + the R8 `-optimize` ProGuard file |
17
+ | Config plugin | `['@oxy.so/app-preset', {}]` | iOS keychain entitlement + `expo-build-properties` + `@oxy.so/services/plugins/withOxySharedPermissions` (which signs every release with the ecosystem key, see below) + the R8 `-optimize` ProGuard file + one APK per ABI |
18
18
  | Android WebP resources | `@oxy.so/app-preset/plugin/withOxyAndroidWebp` | re-encoding generated mipmaps/splash bitmaps to real lossless WebP (opt-in, needs `sharp`) |
19
19
  | Oxy Updates (OTA) | `@oxy.so/app-preset/plugin/withOxyUpdates` | the `expo-updates` manifest URL, release channel, `runtimeVersion` policy and the shared code-signing certificate, required (opt-in, see below) |
20
20
  | Metro | `@oxy.so/app-preset/metro` | monorepo watch folders, block list, symlink + package-exports resolution, web-font/wasm asset exts, release minifier, NativeWind wrapper |
@@ -186,6 +186,36 @@ bump it for a native change and the next push to main releases a new binary
186
186
  (oxy's `android-release.yml`, docs/engineering/build-and-deploy.md#native-android-releases);
187
187
  a JS-only change keeps the version and ships as an OTA update.
188
188
 
189
+ #### One APK per ABI (always on, 6.1.0+)
190
+
191
+ `withOxyAbiSplits`, applied by the preset and by `withOxyUpdates`, adds Gradle
192
+ ABI splits to `android/app/build.gradle`, so `assembleRelease` writes one APK per
193
+ ABI and no universal APK:
194
+
195
+ | APK | For |
196
+ | --- | --- |
197
+ | `app-arm64-v8a-release.apk` | almost every phone and tablet, anything from about 2017 on |
198
+ | `app-armeabi-v7a-release.apk` | older phones, and Android TVs and TV boxes |
199
+
200
+ A universal APK carries every ABI's native libraries and a phone loads one
201
+ (Mention: 126 MB, of which 55 MB arm64-v8a and 37 MB armeabi-v7a libraries).
202
+ `bundleRelease` is unaffected: the AAB keeps every ABI and Google Play serves
203
+ each device its slice.
204
+
205
+ A build that compiles none of those ABIs splits to the ones it compiles, so
206
+ `expo run:android` on an x86_64 emulator (it passes
207
+ `-PreactNativeArchitectures=x86_64`) still gets `app-x86_64-debug.apk`, which the
208
+ Expo CLI installs by the device's ABI. An ABI that is not compiled never gets
209
+ an APK of its own, since it would carry no native libraries.
210
+
211
+ Both release APKs have the app's one `versionCode`. They are the same version of
212
+ the same app, so Android installs either over the other; Google Play's rule of a
213
+ distinct versionCode per APK applies only to APKs uploaded to Play, and Play
214
+ gets the AAB. A `build.gradle` that already has a `splits {}` block (an app's own
215
+ plugin) fails prebuild: remove it. The release workflow
216
+ (docs/engineering/build-and-deploy.md#native-android-releases) publishes the two
217
+ APKs and fails a build without them.
218
+
189
219
  #### Android WebP resources (opt-in)
190
220
 
191
221
  `withOxyAndroidWebp` needs `sharp` installed, so it is registered explicitly:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/app-preset",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
5
5
  "main": "./app.plugin.js",
6
6
  "publishConfig": {
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Expo Config Plugin: withOxyAbiSplits (always applied by the preset)
3
+ *
4
+ * Builds one APK per ABI instead of one universal APK. A universal Oxy APK
5
+ * carries the native libraries of every ABI, of which a phone loads one
6
+ * (Mention 126 MB: 55 MB of arm64-v8a libraries, 37 MB of armeabi-v7a), so a
7
+ * release ships
8
+ *
9
+ * app-arm64-v8a-release.apk every phone from about 2017 on
10
+ * app-armeabi-v7a-release.apk older phones and many Android TVs
11
+ *
12
+ * and no universal APK. Gradle's ABI splits only affect APKs: `bundleRelease`
13
+ * still builds one AAB with every ABI, and Google Play serves each device its
14
+ * own slice of it.
15
+ *
16
+ * A build for ONE device keeps working: `expo run:android` passes
17
+ * `-PreactNativeArchitectures=<the device's ABI>` for a debug build, so the
18
+ * split follows the ABIs Gradle compiles whenever none of the release ABIs is
19
+ * among them (an x86_64 emulator gets `app-x86_64-debug.apk`, which the Expo
20
+ * CLI finds by the device's ABI). A release ABI that is not compiled is never
21
+ * split out, because its APK would carry no native libraries.
22
+ *
23
+ * Every split APK has the app's one `versionCode` (`withOxyReleaseVersion`).
24
+ * That is what sideloading needs: they are the same version of the same app,
25
+ * and Android installs either over the other. Unique versionCodes per APK are
26
+ * a Google Play rule for publishing several APKs to Play; Play gets the AAB.
27
+ *
28
+ * Applied by the preset and by `withOxyUpdates`, the entry every app on the
29
+ * release pipeline lists, so it is idempotent: the second run finds its marker
30
+ * and changes nothing. A build.gradle that already has a `splits {}` block
31
+ * (another plugin's, or a hand edit) fails: two sources for the APK layout is
32
+ * how a release ends up shipping the wrong files.
33
+ */
34
+ const { withAppBuildGradle } = require('expo/config-plugins');
35
+
36
+ const PLUGIN = '[@oxy.so/app-preset withOxyAbiSplits]';
37
+ const MARKER = '@generated oxy-abi-splits';
38
+
39
+ /** The ABIs every Oxy release ships an APK for, in the order people should pick them. */
40
+ const RELEASE_ABIS = ['arm64-v8a', 'armeabi-v7a'];
41
+
42
+ /** Inserted before `android {`: which APKs this build splits out. */
43
+ const RESOLVE_ABIS = `// ${MARKER}: one APK per ABI, no universal APK (@oxy.so/app-preset
44
+ // withOxyAbiSplits). Edit the plugin, never this file. A release ships ${RELEASE_ABIS.join(' and ')};
45
+ // a build that compiles none of them (-PreactNativeArchitectures=x86_64, as \`expo run:android\`
46
+ // passes for an emulator) splits to the ABIs it compiles, so that device still gets an APK.
47
+ def oxyBuiltAbis = (findProperty('reactNativeArchitectures') ?: 'armeabi-v7a,arm64-v8a,x86,x86_64').toString().split(',').collect { it.trim() }.findAll { it }
48
+ def oxyReleaseAbis = [${RELEASE_ABIS.map((abi) => `'${abi}'`).join(', ')}].findAll { oxyBuiltAbis.contains(it) }
49
+ def oxyApkAbis = oxyReleaseAbis ?: oxyBuiltAbis
50
+
51
+ `;
52
+
53
+ /** Inserted as the first entry of `android {`. */
54
+ const SPLITS = `
55
+ // ${MARKER}: the APKs are oxyApkAbis, one each; the AAB is unaffected.
56
+ splits {
57
+ abi {
58
+ reset()
59
+ enable true
60
+ universalApk false
61
+ include(*oxyApkAbis)
62
+ }
63
+ }
64
+ `;
65
+
66
+ function fail(message) {
67
+ throw new Error(`${PLUGIN} ${message}`);
68
+ }
69
+
70
+ /**
71
+ * Apply the split to the text of a Groovy `android/app/build.gradle`. Idempotent.
72
+ *
73
+ * @param {string} contents
74
+ * @returns {string}
75
+ */
76
+ function applyAbiSplits(contents) {
77
+ if (contents.includes(MARKER)) return contents;
78
+
79
+ if (/^\s*splits\s*\{/m.test(contents)) {
80
+ fail(
81
+ 'app/build.gradle already has a `splits {}` block written by another plugin or by hand. ' +
82
+ 'Remove it: the preset splits every Oxy APK by ABI.',
83
+ );
84
+ }
85
+
86
+ const androidBlock = /^android \{$/m;
87
+ if (!androidBlock.test(contents)) {
88
+ fail(
89
+ 'Could not find the top-level `android {` block in app/build.gradle. The Expo template changed: update this plugin instead of editing android/ by hand.',
90
+ );
91
+ }
92
+ return contents.replace(androidBlock, `${RESOLVE_ABIS}android {${SPLITS}`);
93
+ }
94
+
95
+ /** @param {import('expo/config').ExpoConfig} config */
96
+ module.exports = function withOxyAbiSplits(config) {
97
+ return withAppBuildGradle(config, (modConfig) => {
98
+ if (modConfig.modResults.language !== 'groovy') {
99
+ fail(
100
+ `app/build.gradle is ${modConfig.modResults.language}, not Groovy. Oxy releases ship one APK per ABI; ` +
101
+ 'add the split to this plugin for that language instead of shipping a universal APK.',
102
+ );
103
+ }
104
+ modConfig.modResults.contents = applyAbiSplits(modConfig.modResults.contents);
105
+ return modConfig;
106
+ });
107
+ };
108
+ module.exports.applyAbiSplits = applyAbiSplits;
109
+ module.exports.RELEASE_ABIS = RELEASE_ABIS;
@@ -35,6 +35,8 @@
35
35
  * does not carry its certificate; an app lists no signing plugin of its own.
36
36
  * `withOxyReleaseVersion` (always applied) derives Android `versionCode` and iOS
37
37
  * `buildNumber` from `version` (1.2.3 → 1002003); an app sets neither.
38
+ * `withOxyAbiSplits` (always applied) builds one APK per ABI (arm64-v8a,
39
+ * armeabi-v7a) instead of a universal APK; the AAB is unaffected.
38
40
  * `withOxyR8Optimize` (always applied) swaps in R8's `-optimize` ProGuard file on
39
41
  * Expo SDK 56/57 and is a no-op on 58.
40
42
  *
@@ -58,6 +60,7 @@ const withOxyKeychain = require('./withOxyKeychain');
58
60
  const withOxyBuildProperties = require('./withOxyBuildProperties');
59
61
  const withOxyR8Optimize = require('./withOxyR8Optimize');
60
62
  const withOxyReleaseVersion = require('./withOxyReleaseVersion');
63
+ const withOxyAbiSplits = require('./withOxyAbiSplits');
61
64
  const { dirname, join } = require('node:path');
62
65
  const { projectRootOf, requireFromProject, resolveFromProject } = require('./requireFromProject');
63
66
 
@@ -107,6 +110,7 @@ module.exports = function withOxyAppPreset(config, options = {}) {
107
110
 
108
111
  next = withOxyR8Optimize(next);
109
112
  next = withOxyReleaseVersion(next);
113
+ next = withOxyAbiSplits(next);
110
114
 
111
115
  let withOxySharedPermissions;
112
116
  try {
@@ -69,6 +69,7 @@ const fs = require('fs');
69
69
  const path = require('path');
70
70
  const { WarningAggregator } = require('expo/config-plugins');
71
71
  const withOxyReleaseVersion = require('./withOxyReleaseVersion');
72
+ const withOxyAbiSplits = require('./withOxyAbiSplits');
72
73
 
73
74
  /** Origin of the Oxy Updates server. `updates.oxy.so` does not exist; oxy-api serves it. */
74
75
  const DEFAULT_API_ORIGIN = 'https://api.oxy.so';
@@ -182,6 +183,7 @@ module.exports = function withOxyUpdates(config, options = {}) {
182
183
  }
183
184
 
184
185
  // `version` is the OTA boundary, so it also numbers the store build: an
185
- // OTA-enabled app that skips the preset's main plugin gets the same rule.
186
- return withOxyReleaseVersion(next);
186
+ // OTA-enabled app that skips the preset's main plugin gets the same rule,
187
+ // and the same per-ABI APKs (every app on the release pipeline lists this).
188
+ return withOxyAbiSplits(withOxyReleaseVersion(next));
187
189
  };