From 81a93ad1cff3e9788534c22d21bfe1c9f0786b16 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Wed, 24 Mar 2021 20:54:26 -0400 Subject: [PATCH 1/2] Allow configuring ndk build architectures --- ReactAndroid/build.gradle | 9 +++++++++ packages/rn-tester/android/app/build.gradle | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 80d11371b89d1e..3f0c654f58a059 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -326,6 +326,14 @@ def reactNativeInspectorProxyPort() { return value != null ? value : reactNativeDevServerPort() } +def reactNativeArchitectures() { + def isDebug = gradle.startParameter.taskRequests.any { + it.args.any { it.endsWith("Debug") } + } + def value = project.getProperties().get("reactNativeDebugArchitectures") + return value != null && isDebug ? value : "all" +} + def getNdkBuildFullPath() { def ndkBuildFullPath = findNdkBuildFullPath() if (ndkBuildFullPath == null) { @@ -355,6 +363,7 @@ def buildReactNdkLib = tasks.register("buildReactNdkLib", Exec) { inputs.dir("src/main/java/com/facebook/react/modules/blob") outputs.dir("$buildDir/react-ndk/all") commandLine(getNdkBuildFullPath(), + "APP_ABI=${reactNativeArchitectures()}", "NDK_DEBUG=" + (nativeBuildType.equalsIgnoreCase("debug") ? "1" : "0"), "NDK_PROJECT_PATH=null", "NDK_APPLICATION_MK=$projectDir/src/main/jni/Application.mk", diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 6597a0ecdf0f4b..7a5d273484a88e 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -128,6 +128,11 @@ def enableFabric = project.ext.react.enableFabric */ def useIntlJsc = false +/** + * Architectures to build native code for in debug. + */ +def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures") + android { compileSdkVersion 29 ndkVersion ANDROID_NDK_VERSION @@ -176,6 +181,11 @@ android { debug { debuggable true signingConfig signingConfigs.release + if (nativeArchitectures) { + ndk { + abiFilters nativeArchitectures.split(',') + } + } } release { debuggable false @@ -251,7 +261,6 @@ if (enableCodegen) { defaultConfig { externalNativeBuild { ndkBuild { - abiFilters "armeabi-v7a", "x86", "x86_64", "arm64-v8a" arguments "APP_PLATFORM=android-21", "APP_STL=c++_shared", "NDK_TOOLCHAIN_VERSION=clang", From 0f0cd661267b6aa79f8ae3d173c4b43e6b9ca756 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Tue, 6 Jul 2021 14:55:03 -0400 Subject: [PATCH 2/2] Update template --- template/android/app/build.gradle | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index 3e76ea0e075e8b..3fd5f4275c0f64 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -120,6 +120,11 @@ def jscFlavor = 'org.webkit:android-jsc:+' */ def enableHermes = project.ext.react.get("enableHermes", false); +/** + * Architectures to build native code for in debug. + */ +def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures") + android { ndkVersion rootProject.ext.ndkVersion @@ -151,6 +156,11 @@ android { buildTypes { debug { signingConfig signingConfigs.debug + if (nativeArchitectures) { + ndk { + abiFilters nativeArchitectures.split(',') + } + } } release { // Caution! In production, you need to generate your own keystore file.