Skip to content

feat: add option to build only active architectures on android #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/platform-android/src/commands/runAndroid/adb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,29 @@ function getAvailableCPUs(adbPath: string, device: string): Array<string> {
}
}

/**
* Gets the CPU architecture of a device from ADB
*/
function getCPU(adbPath: string, device: string): string | null {
try {
const cpus = execFileSync(adbPath, [
'-s',
device,
'shell',
'getprop',
'ro.product.cpu.abi',
])
.toString()
.trim();

return cpus.length > 0 ? cpus : null;
} catch (e) {
return null;
}
}

export default {
getDevices,
getAvailableCPUs,
getCPU,
};
7 changes: 7 additions & 0 deletions packages/platform-android/src/commands/runAndroid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface Flags {
port: number;
terminal: string;
jetifier: boolean;
activeArchOnly: boolean;
}

type AndroidProject = NonNullable<Config['project']['android']>;
Expand Down Expand Up @@ -380,5 +381,11 @@ export default {
description:
'Do not run "jetifier" – the AndroidX transition tool. By default it runs before Gradle to ease working with libraries that don\'t support AndroidX yet. See more at: https://www.npmjs.com/package/jetifier.',
},
{
name: '--active-arch-only',
description:
'Build native libraries only for the current device architecture for debug builds.',
default: false,
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ async function runOnAllDevices(
gradleArgs.push('-PreactNativeDevServerPort=' + args.port);
}

if (args.activeArchOnly) {
const architectures = devices
.map((device) => {
return adb.getCPU(adbPath, device);
})
.filter((arch) => arch != null);
if (architectures.length > 0) {
logger.info(`Detected architectures ${architectures.join(', ')}`);
gradleArgs.push(
'-PreactNativeDebugArchitectures=' + architectures.join(','),
);
}
}

logger.info('Installing the app...');
logger.debug(
`Running command "cd android && ${cmd} ${gradleArgs.join(' ')}"`,
Expand Down