Skip to content

Commit 0ebe96c

Browse files
feat: add option to build only active architectures on android (react-native-community#1388)
1 parent 2705d9d commit 0ebe96c

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

packages/platform-android/src/commands/runAndroid/adb.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,29 @@ function getAvailableCPUs(adbPath: string, device: string): Array<string> {
6767
}
6868
}
6969

70+
/**
71+
* Gets the CPU architecture of a device from ADB
72+
*/
73+
function getCPU(adbPath: string, device: string): string | null {
74+
try {
75+
const cpus = execFileSync(adbPath, [
76+
'-s',
77+
device,
78+
'shell',
79+
'getprop',
80+
'ro.product.cpu.abi',
81+
])
82+
.toString()
83+
.trim();
84+
85+
return cpus.length > 0 ? cpus : null;
86+
} catch (e) {
87+
return null;
88+
}
89+
}
90+
7091
export default {
7192
getDevices,
7293
getAvailableCPUs,
94+
getCPU,
7395
};

packages/platform-android/src/commands/runAndroid/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface Flags {
5151
port: number;
5252
terminal: string;
5353
jetifier: boolean;
54+
activeArchOnly: boolean;
5455
}
5556

5657
type AndroidProject = NonNullable<Config['project']['android']>;
@@ -380,5 +381,11 @@ export default {
380381
description:
381382
'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.',
382383
},
384+
{
385+
name: '--active-arch-only',
386+
description:
387+
'Build native libraries only for the current device architecture for debug builds.',
388+
default: false,
389+
},
383390
],
384391
};

packages/platform-android/src/commands/runAndroid/runOnAllDevices.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ async function runOnAllDevices(
6363
gradleArgs.push('-PreactNativeDevServerPort=' + args.port);
6464
}
6565

66+
if (args.activeArchOnly) {
67+
const architectures = devices
68+
.map((device) => {
69+
return adb.getCPU(adbPath, device);
70+
})
71+
.filter((arch) => arch != null);
72+
if (architectures.length > 0) {
73+
logger.info(`Detected architectures ${architectures.join(', ')}`);
74+
gradleArgs.push(
75+
'-PreactNativeDebugArchitectures=' + architectures.join(','),
76+
);
77+
}
78+
}
79+
6680
logger.info('Installing the app...');
6781
logger.debug(
6882
`Running command "cd android && ${cmd} ${gradleArgs.join(' ')}"`,

0 commit comments

Comments
 (0)