@hot-updater/android-helper 1.2.0-rc.46 → 1.2.0-rc.48
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/dist/index.cjs +126 -49
- package/dist/index.mjs +126 -49
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -100,6 +100,75 @@ const formatCommand = (words, width = 74) => {
|
|
|
100
100
|
return lines.join("\n");
|
|
101
101
|
};
|
|
102
102
|
//#endregion
|
|
103
|
+
//#region src/utils/windowsGradle.ts
|
|
104
|
+
/**
|
|
105
|
+
* The init script every Windows build runs with. ninja 1.10.2, which the
|
|
106
|
+
* Android SDK's CMake 3.22.1 ships, can't reach a path over MAX_PATH (260
|
|
107
|
+
* characters), and React Native's codegen object paths, which repeat the
|
|
108
|
+
* project's path, pass it. At 259, CMake hashes the long part of an object's
|
|
109
|
+
* name so the whole path stays within it; at 250, an object directory of
|
|
110
|
+
* 179 characters left no room for the hash and a 40-character file name.
|
|
111
|
+
* Only the names of objects under `.cxx` change, never what they compile
|
|
112
|
+
* to.
|
|
113
|
+
*
|
|
114
|
+
* Expo's root project plugin (expo-modules-autolinking 58,
|
|
115
|
+
* `ExpoRootProjectPlugin.kt` `setDefaultCmakeObjectPathMax`) gives every
|
|
116
|
+
* module `-DCMAKE_OBJECT_PATH_MAX` from the `expo.android.cmakeObjectPathMax`
|
|
117
|
+
* property, 1024 when unset, which it reads with `findProperty` as a string
|
|
118
|
+
* when it applies. So the script sets that property on the root project
|
|
119
|
+
* first, unless gradle.properties, the user's, `-P` or the environment set
|
|
120
|
+
* it. Their value stands, `0` included, which turns Expo's limit off and
|
|
121
|
+
* leaves CMake's own: then no module gets one from this script either. A
|
|
122
|
+
* module whose own CMake arguments set CMAKE_OBJECT_PATH_MAX, in its default
|
|
123
|
+
* config, a build type or a flavor, keeps its own.
|
|
124
|
+
*/
|
|
125
|
+
const WINDOWS_INIT_SCRIPT = `// Written by hot-updater for one Windows build: object paths within MAX_PATH.
|
|
126
|
+
// Set by the project, a person or the environment, not this script: their
|
|
127
|
+
// value stands, and 0, which turns Expo's limit off, too.
|
|
128
|
+
def expoLimitSetElsewhere = false
|
|
129
|
+
gradle.rootProject { root ->
|
|
130
|
+
if (root.hasProperty('expo.android.cmakeObjectPathMax')) {
|
|
131
|
+
expoLimitSetElsewhere = true
|
|
132
|
+
} else {
|
|
133
|
+
root.ext.set('expo.android.cmakeObjectPathMax', '259')
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
allprojects { project ->
|
|
137
|
+
['com.android.application', 'com.android.library'].each { id ->
|
|
138
|
+
project.plugins.withId(id) {
|
|
139
|
+
project.extensions.getByName('androidComponents').finalizeDsl { android ->
|
|
140
|
+
def configs = [android.defaultConfig] + android.buildTypes.toList() + android.productFlavors.toList()
|
|
141
|
+
def own = configs.any { config ->
|
|
142
|
+
config.externalNativeBuild.cmake.arguments.any { it.startsWith('-DCMAKE_OBJECT_PATH_MAX') }
|
|
143
|
+
}
|
|
144
|
+
if (!own && !expoLimitSetElsewhere) {
|
|
145
|
+
android.defaultConfig.externalNativeBuild.cmake.arguments.add('-DCMAKE_OBJECT_PATH_MAX=259')
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
/**
|
|
153
|
+
* Runs `build` with the Gradle arguments a Windows build needs: none
|
|
154
|
+
* elsewhere. The init script is written outside the project, and removed
|
|
155
|
+
* after.
|
|
156
|
+
*/
|
|
157
|
+
const withWindowsGradleArgs = async (build) => {
|
|
158
|
+
if (!process.platform.startsWith("win")) return build([]);
|
|
159
|
+
const directory = await fs.default.promises.mkdtemp(path.default.join(os.default.tmpdir(), "hot-updater-windows-"));
|
|
160
|
+
try {
|
|
161
|
+
const script = path.default.join(directory, "windows.init.gradle");
|
|
162
|
+
await fs.default.promises.writeFile(script, WINDOWS_INIT_SCRIPT);
|
|
163
|
+
return await build(["--init-script", script]);
|
|
164
|
+
} finally {
|
|
165
|
+
await fs.default.promises.rm(directory, {
|
|
166
|
+
recursive: true,
|
|
167
|
+
force: true
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
//#endregion
|
|
103
172
|
//#region src/builder/runGradle.ts
|
|
104
173
|
/** Why Gradle failed, without its command line. */
|
|
105
174
|
const describeFailure = (error) => {
|
|
@@ -116,9 +185,10 @@ function getTaskNames(moduleName, tasks) {
|
|
|
116
185
|
return tasks.map((task) => `${moduleName}:${task}`);
|
|
117
186
|
}
|
|
118
187
|
/**
|
|
119
|
-
*
|
|
188
|
+
* The project's Gradle wrapper. On Windows by its path: cmd.exe finds no
|
|
189
|
+
* program in the current directory with NoDefaultCurrentDirectoryInExePath.
|
|
120
190
|
*/
|
|
121
|
-
const getGradleWrapper = () => process.platform.startsWith("win") ? "gradlew.bat" : "./gradlew";
|
|
191
|
+
const getGradleWrapper = (androidProjectPath) => process.platform.startsWith("win") ? path.default.join(androidProjectPath, "gradlew.bat") : "./gradlew";
|
|
122
192
|
/** A variable a POSIX shell can't name, as the signing environment's are. */
|
|
123
193
|
const isShellName = (name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);
|
|
124
194
|
/**
|
|
@@ -127,8 +197,8 @@ const isShellName = (name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);
|
|
|
127
197
|
* a shell name, such as `ORG_GRADLE_PROJECT_android.injected.signing.store.file`:
|
|
128
198
|
* the build then signs with the project's own config. bash keeps them.
|
|
129
199
|
*/
|
|
130
|
-
const gradleCommand = (env) => {
|
|
131
|
-
const wrapper = getGradleWrapper();
|
|
200
|
+
const gradleCommand = (androidProjectPath, env) => {
|
|
201
|
+
const wrapper = getGradleWrapper(androidProjectPath);
|
|
132
202
|
return wrapper === "./gradlew" && Object.keys(env ?? {}).some((name) => !isShellName(name)) ? ["bash", [wrapper]] : [wrapper, []];
|
|
133
203
|
};
|
|
134
204
|
/**
|
|
@@ -151,46 +221,49 @@ async function runGradleTasks({ tasks, logPrefix, args, env, androidProjectPath,
|
|
|
151
221
|
gradleArgs.push("-x", "lint");
|
|
152
222
|
if (args.extraParams) gradleArgs.push(...args.extraParams);
|
|
153
223
|
if ("port" in args && args.port != null) gradleArgs.push(`-PreactNativeDevServerPort=${args.port}`);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
const [command, prefix] = gradleCommand(env);
|
|
169
|
-
const gradle = (0, execa.execa)(command, [...prefix, ...gradleArgs], {
|
|
170
|
-
cwd: androidProjectPath,
|
|
171
|
-
env,
|
|
172
|
-
all: true,
|
|
173
|
-
buffer: false
|
|
224
|
+
return withWindowsGradleArgs(async (platformArgs) => {
|
|
225
|
+
const finalArgs = [...gradleArgs, ...platformArgs];
|
|
226
|
+
const logger = createGradleLogger({ logPrefix });
|
|
227
|
+
await logger.start({
|
|
228
|
+
title: `Building ${tasks.join(", ")}`,
|
|
229
|
+
header: [
|
|
230
|
+
...logHeader,
|
|
231
|
+
`Project ${path.default.relative((0, _hot_updater_cli_tools.getCwd)(), androidProjectPath) || "."}`,
|
|
232
|
+
`App module ${appModuleName}`,
|
|
233
|
+
`Tasks ${tasks.join(", ")}`,
|
|
234
|
+
`$ ${formatCommand([path.default.basename(getGradleWrapper(androidProjectPath)), ...finalArgs])}`,
|
|
235
|
+
""
|
|
236
|
+
]
|
|
174
237
|
});
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
238
|
+
let logFilePath = null;
|
|
239
|
+
try {
|
|
240
|
+
const [command, prefix] = gradleCommand(androidProjectPath, env);
|
|
241
|
+
const gradle = (0, execa.execa)(command, [...prefix, ...finalArgs], {
|
|
242
|
+
cwd: androidProjectPath,
|
|
243
|
+
env,
|
|
244
|
+
all: true,
|
|
245
|
+
buffer: false
|
|
246
|
+
});
|
|
247
|
+
const outputStream = gradle.all ?? gradle.stdout;
|
|
248
|
+
const [gradleResult, loggingResult] = await Promise.allSettled([gradle, outputStream ? logger.processStream(outputStream) : void 0]);
|
|
249
|
+
if (gradleResult.status === "rejected") throw gradleResult.reason;
|
|
250
|
+
if (loggingResult.status === "rejected") throw loggingResult.reason;
|
|
251
|
+
logger.stop(`Built ${tasks.join(", ")}`);
|
|
252
|
+
logFilePath = logger.logFilePath;
|
|
253
|
+
} catch (e) {
|
|
254
|
+
logger.writeError(e);
|
|
255
|
+
const reason = describeFailure(e);
|
|
256
|
+
logger.stop(`Build failed · ${reason.replace(/\.$/, "")}`, false);
|
|
257
|
+
throw new _hot_updater_cli_tools.BuildFailedError(`Build failed: ${reason}`, {
|
|
258
|
+
logPath: logger.logPath,
|
|
259
|
+
summary: logger.failureSummary,
|
|
260
|
+
cause: e
|
|
261
|
+
});
|
|
262
|
+
} finally {
|
|
263
|
+
await logger.close();
|
|
264
|
+
}
|
|
265
|
+
return logFilePath;
|
|
266
|
+
});
|
|
194
267
|
}
|
|
195
268
|
/**
|
|
196
269
|
* Find the build output directory and artifact path
|
|
@@ -360,6 +433,8 @@ const findAapt2 = (androidProjectPath) => {
|
|
|
360
433
|
return fs.default.readdirSync(buildTools).sort(compareVersions).reverse().map((version) => path.default.join(buildTools, version, executable)).find((aapt2) => fs.default.existsSync(aapt2));
|
|
361
434
|
};
|
|
362
435
|
const RAW_MARKER = "\" (Raw: \"";
|
|
436
|
+
/** aapt2's output lines: aapt2.exe ends each with CRLF. */
|
|
437
|
+
const outputLines = (output) => output.split(/\r?\n/);
|
|
363
438
|
/**
|
|
364
439
|
* An attribute aapt2 prints as `="<value>" (Raw: "<value>")`, given the text
|
|
365
440
|
* after `="`. aapt2 does not escape the value, so it is the prefix the rest
|
|
@@ -387,21 +462,23 @@ const readAttribute = (line, marker) => {
|
|
|
387
462
|
* A `<meta-data>` value from `aapt2 dump xmltree` of the manifest: the
|
|
388
463
|
* literal, or a resource reference such as `@string/channel`. null when the
|
|
389
464
|
* manifest has none, and undefined when aapt2 printed one it cannot read
|
|
390
|
-
* exactly.
|
|
465
|
+
* exactly, or a meta-data whose name it cannot read.
|
|
391
466
|
*/
|
|
392
467
|
const parseManifestMetaData = (xmltree, name) => {
|
|
393
|
-
const lines = xmltree
|
|
468
|
+
const lines = outputLines(xmltree);
|
|
469
|
+
let unreadable = false;
|
|
394
470
|
for (let i = 0; i < lines.length; i++) {
|
|
395
471
|
if (!/^\s*E: meta-data\b/.test(lines[i])) continue;
|
|
396
472
|
let metaDataName = null;
|
|
397
473
|
let value = null;
|
|
398
474
|
for (let j = i + 1; j < lines.length && /^\s*A: /.test(lines[j]); j++) {
|
|
399
|
-
metaDataName
|
|
475
|
+
if (metaDataName === null) metaDataName = readAttribute(lines[j], ":name(0x01010003)=");
|
|
400
476
|
if (value === null) value = readAttribute(lines[j], ":value(0x01010024)=");
|
|
401
477
|
}
|
|
402
478
|
if (metaDataName === name) return value ?? void 0;
|
|
479
|
+
if (metaDataName === void 0) unreadable = true;
|
|
403
480
|
}
|
|
404
|
-
return null;
|
|
481
|
+
return unreadable ? void 0 : null;
|
|
405
482
|
};
|
|
406
483
|
/**
|
|
407
484
|
* The `android:versionName` of the `<manifest>` element in `aapt2 dump
|
|
@@ -409,7 +486,7 @@ const parseManifestMetaData = (xmltree, name) => {
|
|
|
409
486
|
* without one, and undefined when it cannot be read exactly.
|
|
410
487
|
*/
|
|
411
488
|
const parseManifestVersionName = (xmltree) => {
|
|
412
|
-
for (const line of xmltree
|
|
489
|
+
for (const line of outputLines(xmltree)) {
|
|
413
490
|
const value = readAttribute(line, ":versionName(0x0101021c)=");
|
|
414
491
|
if (value !== null) return value;
|
|
415
492
|
}
|
|
@@ -429,7 +506,7 @@ const parseManifestVersionCode = (xmltree) => {
|
|
|
429
506
|
* table has none aapt2 printed on one line.
|
|
430
507
|
*/
|
|
431
508
|
const parseResourceString = (resources, reference) => {
|
|
432
|
-
const lines = resources
|
|
509
|
+
const lines = outputLines(resources);
|
|
433
510
|
const start = lines.findIndex((line) => {
|
|
434
511
|
const [, id, name] = line.match(/^\s*resource (0x[0-9a-f]+) (\S+)/) ?? [];
|
|
435
512
|
return id !== void 0 && (reference === `@${id}` || reference === `@${name}`);
|
package/dist/index.mjs
CHANGED
|
@@ -72,6 +72,75 @@ const formatCommand = (words, width = 74) => {
|
|
|
72
72
|
return lines.join("\n");
|
|
73
73
|
};
|
|
74
74
|
//#endregion
|
|
75
|
+
//#region src/utils/windowsGradle.ts
|
|
76
|
+
/**
|
|
77
|
+
* The init script every Windows build runs with. ninja 1.10.2, which the
|
|
78
|
+
* Android SDK's CMake 3.22.1 ships, can't reach a path over MAX_PATH (260
|
|
79
|
+
* characters), and React Native's codegen object paths, which repeat the
|
|
80
|
+
* project's path, pass it. At 259, CMake hashes the long part of an object's
|
|
81
|
+
* name so the whole path stays within it; at 250, an object directory of
|
|
82
|
+
* 179 characters left no room for the hash and a 40-character file name.
|
|
83
|
+
* Only the names of objects under `.cxx` change, never what they compile
|
|
84
|
+
* to.
|
|
85
|
+
*
|
|
86
|
+
* Expo's root project plugin (expo-modules-autolinking 58,
|
|
87
|
+
* `ExpoRootProjectPlugin.kt` `setDefaultCmakeObjectPathMax`) gives every
|
|
88
|
+
* module `-DCMAKE_OBJECT_PATH_MAX` from the `expo.android.cmakeObjectPathMax`
|
|
89
|
+
* property, 1024 when unset, which it reads with `findProperty` as a string
|
|
90
|
+
* when it applies. So the script sets that property on the root project
|
|
91
|
+
* first, unless gradle.properties, the user's, `-P` or the environment set
|
|
92
|
+
* it. Their value stands, `0` included, which turns Expo's limit off and
|
|
93
|
+
* leaves CMake's own: then no module gets one from this script either. A
|
|
94
|
+
* module whose own CMake arguments set CMAKE_OBJECT_PATH_MAX, in its default
|
|
95
|
+
* config, a build type or a flavor, keeps its own.
|
|
96
|
+
*/
|
|
97
|
+
const WINDOWS_INIT_SCRIPT = `// Written by hot-updater for one Windows build: object paths within MAX_PATH.
|
|
98
|
+
// Set by the project, a person or the environment, not this script: their
|
|
99
|
+
// value stands, and 0, which turns Expo's limit off, too.
|
|
100
|
+
def expoLimitSetElsewhere = false
|
|
101
|
+
gradle.rootProject { root ->
|
|
102
|
+
if (root.hasProperty('expo.android.cmakeObjectPathMax')) {
|
|
103
|
+
expoLimitSetElsewhere = true
|
|
104
|
+
} else {
|
|
105
|
+
root.ext.set('expo.android.cmakeObjectPathMax', '259')
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
allprojects { project ->
|
|
109
|
+
['com.android.application', 'com.android.library'].each { id ->
|
|
110
|
+
project.plugins.withId(id) {
|
|
111
|
+
project.extensions.getByName('androidComponents').finalizeDsl { android ->
|
|
112
|
+
def configs = [android.defaultConfig] + android.buildTypes.toList() + android.productFlavors.toList()
|
|
113
|
+
def own = configs.any { config ->
|
|
114
|
+
config.externalNativeBuild.cmake.arguments.any { it.startsWith('-DCMAKE_OBJECT_PATH_MAX') }
|
|
115
|
+
}
|
|
116
|
+
if (!own && !expoLimitSetElsewhere) {
|
|
117
|
+
android.defaultConfig.externalNativeBuild.cmake.arguments.add('-DCMAKE_OBJECT_PATH_MAX=259')
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`;
|
|
124
|
+
/**
|
|
125
|
+
* Runs `build` with the Gradle arguments a Windows build needs: none
|
|
126
|
+
* elsewhere. The init script is written outside the project, and removed
|
|
127
|
+
* after.
|
|
128
|
+
*/
|
|
129
|
+
const withWindowsGradleArgs = async (build) => {
|
|
130
|
+
if (!process.platform.startsWith("win")) return build([]);
|
|
131
|
+
const directory = await fs.promises.mkdtemp(path.join(os.tmpdir(), "hot-updater-windows-"));
|
|
132
|
+
try {
|
|
133
|
+
const script = path.join(directory, "windows.init.gradle");
|
|
134
|
+
await fs.promises.writeFile(script, WINDOWS_INIT_SCRIPT);
|
|
135
|
+
return await build(["--init-script", script]);
|
|
136
|
+
} finally {
|
|
137
|
+
await fs.promises.rm(directory, {
|
|
138
|
+
recursive: true,
|
|
139
|
+
force: true
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
//#endregion
|
|
75
144
|
//#region src/builder/runGradle.ts
|
|
76
145
|
/** Why Gradle failed, without its command line. */
|
|
77
146
|
const describeFailure = (error) => {
|
|
@@ -88,9 +157,10 @@ function getTaskNames(moduleName, tasks) {
|
|
|
88
157
|
return tasks.map((task) => `${moduleName}:${task}`);
|
|
89
158
|
}
|
|
90
159
|
/**
|
|
91
|
-
*
|
|
160
|
+
* The project's Gradle wrapper. On Windows by its path: cmd.exe finds no
|
|
161
|
+
* program in the current directory with NoDefaultCurrentDirectoryInExePath.
|
|
92
162
|
*/
|
|
93
|
-
const getGradleWrapper = () => process.platform.startsWith("win") ? "gradlew.bat" : "./gradlew";
|
|
163
|
+
const getGradleWrapper = (androidProjectPath) => process.platform.startsWith("win") ? path.join(androidProjectPath, "gradlew.bat") : "./gradlew";
|
|
94
164
|
/** A variable a POSIX shell can't name, as the signing environment's are. */
|
|
95
165
|
const isShellName = (name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);
|
|
96
166
|
/**
|
|
@@ -99,8 +169,8 @@ const isShellName = (name) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name);
|
|
|
99
169
|
* a shell name, such as `ORG_GRADLE_PROJECT_android.injected.signing.store.file`:
|
|
100
170
|
* the build then signs with the project's own config. bash keeps them.
|
|
101
171
|
*/
|
|
102
|
-
const gradleCommand = (env) => {
|
|
103
|
-
const wrapper = getGradleWrapper();
|
|
172
|
+
const gradleCommand = (androidProjectPath, env) => {
|
|
173
|
+
const wrapper = getGradleWrapper(androidProjectPath);
|
|
104
174
|
return wrapper === "./gradlew" && Object.keys(env ?? {}).some((name) => !isShellName(name)) ? ["bash", [wrapper]] : [wrapper, []];
|
|
105
175
|
};
|
|
106
176
|
/**
|
|
@@ -123,46 +193,49 @@ async function runGradleTasks({ tasks, logPrefix, args, env, androidProjectPath,
|
|
|
123
193
|
gradleArgs.push("-x", "lint");
|
|
124
194
|
if (args.extraParams) gradleArgs.push(...args.extraParams);
|
|
125
195
|
if ("port" in args && args.port != null) gradleArgs.push(`-PreactNativeDevServerPort=${args.port}`);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
const [command, prefix] = gradleCommand(env);
|
|
141
|
-
const gradle = execa(command, [...prefix, ...gradleArgs], {
|
|
142
|
-
cwd: androidProjectPath,
|
|
143
|
-
env,
|
|
144
|
-
all: true,
|
|
145
|
-
buffer: false
|
|
196
|
+
return withWindowsGradleArgs(async (platformArgs) => {
|
|
197
|
+
const finalArgs = [...gradleArgs, ...platformArgs];
|
|
198
|
+
const logger = createGradleLogger({ logPrefix });
|
|
199
|
+
await logger.start({
|
|
200
|
+
title: `Building ${tasks.join(", ")}`,
|
|
201
|
+
header: [
|
|
202
|
+
...logHeader,
|
|
203
|
+
`Project ${path.relative(getCwd(), androidProjectPath) || "."}`,
|
|
204
|
+
`App module ${appModuleName}`,
|
|
205
|
+
`Tasks ${tasks.join(", ")}`,
|
|
206
|
+
`$ ${formatCommand([path.basename(getGradleWrapper(androidProjectPath)), ...finalArgs])}`,
|
|
207
|
+
""
|
|
208
|
+
]
|
|
146
209
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
210
|
+
let logFilePath = null;
|
|
211
|
+
try {
|
|
212
|
+
const [command, prefix] = gradleCommand(androidProjectPath, env);
|
|
213
|
+
const gradle = execa(command, [...prefix, ...finalArgs], {
|
|
214
|
+
cwd: androidProjectPath,
|
|
215
|
+
env,
|
|
216
|
+
all: true,
|
|
217
|
+
buffer: false
|
|
218
|
+
});
|
|
219
|
+
const outputStream = gradle.all ?? gradle.stdout;
|
|
220
|
+
const [gradleResult, loggingResult] = await Promise.allSettled([gradle, outputStream ? logger.processStream(outputStream) : void 0]);
|
|
221
|
+
if (gradleResult.status === "rejected") throw gradleResult.reason;
|
|
222
|
+
if (loggingResult.status === "rejected") throw loggingResult.reason;
|
|
223
|
+
logger.stop(`Built ${tasks.join(", ")}`);
|
|
224
|
+
logFilePath = logger.logFilePath;
|
|
225
|
+
} catch (e) {
|
|
226
|
+
logger.writeError(e);
|
|
227
|
+
const reason = describeFailure(e);
|
|
228
|
+
logger.stop(`Build failed · ${reason.replace(/\.$/, "")}`, false);
|
|
229
|
+
throw new BuildFailedError(`Build failed: ${reason}`, {
|
|
230
|
+
logPath: logger.logPath,
|
|
231
|
+
summary: logger.failureSummary,
|
|
232
|
+
cause: e
|
|
233
|
+
});
|
|
234
|
+
} finally {
|
|
235
|
+
await logger.close();
|
|
236
|
+
}
|
|
237
|
+
return logFilePath;
|
|
238
|
+
});
|
|
166
239
|
}
|
|
167
240
|
/**
|
|
168
241
|
* Find the build output directory and artifact path
|
|
@@ -332,6 +405,8 @@ const findAapt2 = (androidProjectPath) => {
|
|
|
332
405
|
return fs.readdirSync(buildTools).sort(compareVersions).reverse().map((version) => path.join(buildTools, version, executable)).find((aapt2) => fs.existsSync(aapt2));
|
|
333
406
|
};
|
|
334
407
|
const RAW_MARKER = "\" (Raw: \"";
|
|
408
|
+
/** aapt2's output lines: aapt2.exe ends each with CRLF. */
|
|
409
|
+
const outputLines = (output) => output.split(/\r?\n/);
|
|
335
410
|
/**
|
|
336
411
|
* An attribute aapt2 prints as `="<value>" (Raw: "<value>")`, given the text
|
|
337
412
|
* after `="`. aapt2 does not escape the value, so it is the prefix the rest
|
|
@@ -359,21 +434,23 @@ const readAttribute = (line, marker) => {
|
|
|
359
434
|
* A `<meta-data>` value from `aapt2 dump xmltree` of the manifest: the
|
|
360
435
|
* literal, or a resource reference such as `@string/channel`. null when the
|
|
361
436
|
* manifest has none, and undefined when aapt2 printed one it cannot read
|
|
362
|
-
* exactly.
|
|
437
|
+
* exactly, or a meta-data whose name it cannot read.
|
|
363
438
|
*/
|
|
364
439
|
const parseManifestMetaData = (xmltree, name) => {
|
|
365
|
-
const lines = xmltree
|
|
440
|
+
const lines = outputLines(xmltree);
|
|
441
|
+
let unreadable = false;
|
|
366
442
|
for (let i = 0; i < lines.length; i++) {
|
|
367
443
|
if (!/^\s*E: meta-data\b/.test(lines[i])) continue;
|
|
368
444
|
let metaDataName = null;
|
|
369
445
|
let value = null;
|
|
370
446
|
for (let j = i + 1; j < lines.length && /^\s*A: /.test(lines[j]); j++) {
|
|
371
|
-
metaDataName
|
|
447
|
+
if (metaDataName === null) metaDataName = readAttribute(lines[j], ":name(0x01010003)=");
|
|
372
448
|
if (value === null) value = readAttribute(lines[j], ":value(0x01010024)=");
|
|
373
449
|
}
|
|
374
450
|
if (metaDataName === name) return value ?? void 0;
|
|
451
|
+
if (metaDataName === void 0) unreadable = true;
|
|
375
452
|
}
|
|
376
|
-
return null;
|
|
453
|
+
return unreadable ? void 0 : null;
|
|
377
454
|
};
|
|
378
455
|
/**
|
|
379
456
|
* The `android:versionName` of the `<manifest>` element in `aapt2 dump
|
|
@@ -381,7 +458,7 @@ const parseManifestMetaData = (xmltree, name) => {
|
|
|
381
458
|
* without one, and undefined when it cannot be read exactly.
|
|
382
459
|
*/
|
|
383
460
|
const parseManifestVersionName = (xmltree) => {
|
|
384
|
-
for (const line of xmltree
|
|
461
|
+
for (const line of outputLines(xmltree)) {
|
|
385
462
|
const value = readAttribute(line, ":versionName(0x0101021c)=");
|
|
386
463
|
if (value !== null) return value;
|
|
387
464
|
}
|
|
@@ -401,7 +478,7 @@ const parseManifestVersionCode = (xmltree) => {
|
|
|
401
478
|
* table has none aapt2 printed on one line.
|
|
402
479
|
*/
|
|
403
480
|
const parseResourceString = (resources, reference) => {
|
|
404
|
-
const lines = resources
|
|
481
|
+
const lines = outputLines(resources);
|
|
405
482
|
const start = lines.findIndex((line) => {
|
|
406
483
|
const [, id, name] = line.match(/^\s*resource (0x[0-9a-f]+) (\S+)/) ?? [];
|
|
407
484
|
return id !== void 0 && (reference === `@${id}` || reference === `@${name}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/android-helper",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"execa": "9.5.2",
|
|
31
31
|
"fast-xml-parser": "5.7.2",
|
|
32
32
|
"jszip": "^3.10.1",
|
|
33
|
-
"@hot-updater/cli-tools": "1.2.0-rc.
|
|
34
|
-
"@hot-updater/
|
|
35
|
-
"@hot-updater/
|
|
33
|
+
"@hot-updater/cli-tools": "1.2.0-rc.48",
|
|
34
|
+
"@hot-updater/protocol": "1.2.0-rc.48",
|
|
35
|
+
"@hot-updater/plugin-core": "1.2.0-rc.48"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^20"
|