Skip to content

Commit

Permalink
feat: add option to build only active architectures on android (react…
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis authored Jul 6, 2021
1 parent 2705d9d commit 0ebe96c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
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

0 comments on commit 0ebe96c

Please sign in to comment.