From 0f39a1076dc154995a2db79352adc36452f46210 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 8 Nov 2021 07:19:30 -0800 Subject: [PATCH] Make the `reactNativeArchitectures` property more discoverable Summary: I've unified the function that is responsible of getting the `reactNativeArchitectures` property to a single one (ideally we could move it inside the Gradle Plugin in the future). I've also added a property in the `gradle.properties` file. This makes easier for users to customize the architecture to build without having to specify a CLI flag or edit multiple gradle files. Changelog: [Android] [Added] - Make the `reactNativeArchitectures` property more discoverable Reviewed By: ShikaSD Differential Revision: D32244997 fbshipit-source-id: 33180544400f9abe63e9b539ff16fefa17a024ba --- gradle.properties | 5 +++++ packages/rn-tester/android/app/build.gradle | 9 +++++---- template/android/app/build.gradle | 10 ++++++---- template/android/gradle.properties | 5 +++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4d0bece201bd22..af9ce5ae9b642f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,3 +7,8 @@ org.gradle.parallel=true ANDROID_NDK_VERSION=21.4.7075529 android.useAndroidX=true kotlin_version=1.5.31 + +# Use this property to specify which architecture you want to build. +# You can also override it from the CLI using +# ./gradlew -PreactNativeArchitectures=x86_64 +reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 7a2303617a824f..a2de00ba8fec3b 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -135,9 +135,10 @@ def useIntlJsc = false /** * Architectures to build native code for. */ -def nativeArchitectures = project.getProperties().get("reactNativeArchitectures") ? - project.getProperties().get("reactNativeArchitectures").split(",") - : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] +def reactNativeArchitectures() { + def value = project.getProperties().get("reactNativeArchitectures") + return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] +} android { compileSdkVersion 29 @@ -185,7 +186,7 @@ android { enable enableSeparateBuildPerCPUArchitecture universalApk false reset() - include (*nativeArchitectures) + include (*reactNativeArchitectures()) } } buildTypes { diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index 04130f5c7130df..e1c91549c43251 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -123,9 +123,11 @@ def enableHermes = project.ext.react.get("enableHermes", false); /** * Architectures to build native code for. */ -def nativeArchitectures = project.getProperties().get("reactNativeArchitectures") ? - project.getProperties().get("reactNativeArchitectures").split(",") - : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] +def reactNativeArchitectures() { + def value = project.getProperties().get("reactNativeArchitectures") + return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] +} + android { ndkVersion rootProject.ext.ndkVersion @@ -143,7 +145,7 @@ android { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK - include (*nativeArchitectures) + include (*reactNativeArchitectures()) } } signingConfigs { diff --git a/template/android/gradle.properties b/template/android/gradle.properties index 11d6e02418e0b4..389db0c188079c 100644 --- a/template/android/gradle.properties +++ b/template/android/gradle.properties @@ -26,3 +26,8 @@ android.enableJetifier=true # Version of flipper SDK to use with React Native FLIPPER_VERSION=0.99.0 + +# Use this property to specify which architecture you want to build. +# You can also override it from the CLI using +# ./gradlew -PreactNativeArchitectures=x86_64 +reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64