Skip to content

Commit 111ffb3

Browse files
committed
fix: use aapt instead of node-apk
1 parent a449e29 commit 111ffb3

3 files changed

Lines changed: 46 additions & 22 deletions

File tree

packages/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"@rock-js/tools": "^0.11.13",
3030
"adm-zip": "^0.5.16",
3131
"commander": "^12.1.0",
32-
"node-apk": "^1.2.1",
3332
"tar": "^7.5.1",
3433
"tslib": "^2.3.0"
3534
},

packages/cli/src/lib/plugins/remoteCache.ts

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { execFileSync } from 'node:child_process';
12
import fs from 'node:fs';
23
import os from 'node:os';
34
import path from 'node:path';
@@ -255,7 +256,7 @@ ${output
255256

256257
// Upload index.html for Android ad-hoc distribution
257258
if (args.adHoc && isArtifactAPK) {
258-
const { version, packageName } = await getManifestFromApk(binaryPath);
259+
const { version, packageName } = getManifestFromApk(binaryPath);
259260
const { url: urlIndexHtml, getResponse: getResponseIndexHtml } =
260261
await remoteBuildCache.upload({
261262
artifactName,
@@ -348,20 +349,54 @@ async function getInfoPlistFromIpa(binaryPath: string) {
348349
};
349350
}
350351

351-
async function getManifestFromApk(binaryPath: string) {
352+
function findAapt() {
353+
const sdkRoot =
354+
process.env['ANDROID_HOME'] || process.env['ANDROID_SDK_ROOT'];
355+
356+
if (!sdkRoot) {
357+
throw new RockError(
358+
'ANDROID_HOME or ANDROID_SDK_ROOT environment variable is not set. Please follow instructions at: https://reactnative.dev/docs/set-up-your-environment?platform=android',
359+
);
360+
}
361+
362+
const buildToolsPath = path.join(sdkRoot, 'build-tools');
363+
const versions = fs.readdirSync(buildToolsPath);
364+
365+
for (const version of versions) {
366+
const aaptPath = path.join(buildToolsPath, version, 'aapt');
367+
if (fs.existsSync(aaptPath)) {
368+
logger.debug(`Found aapt at: ${aaptPath}`);
369+
return aaptPath;
370+
}
371+
}
372+
373+
throw new RockError(
374+
`"aapt" not found in Android Build-Tools directory: ${colorLink(buildToolsPath)}
375+
Please follow instructions at: https://reactnative.dev/docs/set-up-your-environment?platform=android`,
376+
);
377+
}
378+
379+
function getManifestFromApk(binaryPath: string) {
352380
const apkFileName = path.basename(binaryPath, '.apk');
353381

354382
try {
355-
const nodeApk = await import('node-apk');
356-
const { Apk } = nodeApk.default || nodeApk;
357-
const apk = new Apk(binaryPath);
358-
const manifest = await apk.getManifestInfo();
359-
apk.close();
383+
const aaptPath = findAapt();
360384

361-
return {
362-
packageName: manifest.package || apkFileName,
363-
version: manifest.versionName || '1.0',
364-
};
385+
const output = execFileSync(aaptPath, ['dump', 'badging', binaryPath], {
386+
encoding: 'utf8',
387+
});
388+
389+
const packageMatch = output?.match(/package: name='([^']+)'/);
390+
const versionMatch = output?.match(/versionName='([^']+)'/);
391+
392+
const packageName = packageMatch?.[1] || apkFileName;
393+
const version = versionMatch?.[1] || '1.0';
394+
395+
logger.debug(
396+
`Extracted APK manifest - package: ${packageName}, version: ${version}`,
397+
);
398+
399+
return { packageName, version };
365400
} catch (error) {
366401
logger.debug('Failed to parse APK manifest, using fallback', error);
367402
return {

pnpm-lock.yaml

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)