From d59425a07dd5fce9e2e0120767144c8c5d12f5c8 Mon Sep 17 00:00:00 2001 From: Sahil Soni Date: Sat, 6 Jun 2026 17:27:09 +0530 Subject: [PATCH] fix(android): respect reactNativeArchitectures to skip unnecessary ABI builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the parent project passes -PreactNativeArchitectures (or -Preact.nativeArchitectures), the android-jsi library currently builds native code for every NDK ABI (arm64-v8a, armeabi-v7a, x86, x86_64, etc.) regardless of the specified filter. This adds an ndk.abiFilters block inside defaultConfig that reads the property from rootProject. When unset the list stays empty, which is a no-op (every ABI is built — same as before). When set, CMake/ninja only compiles for the requested architectures, saving build time and resources. Fixes #___ --- native/android-jsi/build.gradle | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/native/android-jsi/build.gradle b/native/android-jsi/build.gradle index 9ae589d01..68ab1d285 100755 --- a/native/android-jsi/build.gradle +++ b/native/android-jsi/build.gradle @@ -7,6 +7,20 @@ def DEFAULT_MIN_SDK_VERSION = 16 def DEFAULT_TARGET_SDK_VERSION = 28 def DEFAULT_NDK_VERSION = "20.1.5948944" +// Respect reactNativeArchitectures from the parent project to avoid +// building native libraries for unnecessary ABIs (e.g. x86, x86_64). +// Supports both the short 'reactNativeArchitectures' and scoped +// 'react.nativeArchitectures' property names used by React Native. +def reactNativeArchitectures = [] +if (rootProject.hasProperty('reactNativeArchitectures')) { + reactNativeArchitectures = rootProject.property('reactNativeArchitectures').split(',') +} +if (rootProject.hasProperty('react.nativeArchitectures')) { + reactNativeArchitectures = rootProject.property('react.nativeArchitectures').split(',') +} +// When reactNativeArchitectures is empty the ndk block below is a +// no-op — every ABI is built (current default behaviour). + android { compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION @@ -19,6 +33,9 @@ android { targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION versionCode 1 versionName "1.0" + ndk { + abiFilters reactNativeArchitectures + } externalNativeBuild { cmake { // Not sure if this is necessary. I added this in attempt to fix catching