From 5f577135b35553b9fe91145bb6cd2b84d6b12c30 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 7 Apr 2022 09:35:34 -0700 Subject: [PATCH] Improve support for Android users on M1 machine Summary: Currently users on M1 machine can't use the New Architecture correctly as they will get build failures when building the native code. This Diff fixes it by automatically recognizing the host architecture and switching to NDK 24 if user is runnign on `aarch64` Changelog: [Android] [Fixed] - Improve support for Android users on M1 machine Differential Revision: D35468252 fbshipit-source-id: 0d1f7bc3ec514335e9b19af7ea9fe0f9a509d313 --- ReactAndroid/build.gradle | 11 +++++++---- build.gradle.kts | 3 +++ packages/rn-tester/android/app/build.gradle | 11 +++++++---- template/android/build.gradle | 8 +++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 41f7a3ce8be..a45fec99d95 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -252,10 +252,13 @@ android { buildToolsVersion = "31.0.0" compileSdkVersion 31 - // Used to override the NDK path & version on internal CI - if (System.getenv("ANDROID_NDK") != null && System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) { - ndkPath System.getenv("ANDROID_NDK") - ndkVersion System.getenv("LOCAL_ANDROID_NDK_VERSION") + // Used to override the NDK path/version on internal CI or by allowing + // users to customize the NDK path/version from their root project (e.g. for M1 support) + if (rootProject.hasProperty("ndkPath")) { + ndkPath rootProject.ext.ndkPath + } + if (rootProject.hasProperty("ndkVersion")) { + ndkVersion rootProject.ext.ndkVersion } defaultConfig { diff --git a/build.gradle.kts b/build.gradle.kts index f13293a4145..1b3cd9c89e5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,9 @@ * LICENSE file in the root directory of this source tree. */ +val ndkPath by extra(System.getenv("ANDROID_NDK")) +val ndkVersion by extra(System.getenv("ANDROID_NDK_VERSION")) + buildscript { repositories { google() diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 6100303bc10..ae8e5699094 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -146,10 +146,13 @@ android { buildToolsVersion = "31.0.0" compileSdkVersion 31 - // Used to override the NDK path & version on internal CI - if (System.getenv("ANDROID_NDK") != null && System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) { - ndkPath System.getenv("ANDROID_NDK") - ndkVersion System.getenv("LOCAL_ANDROID_NDK_VERSION") + // Used to override the NDK path/version on internal CI or by allowing + // users to customize the NDK path/version from their root project (e.g. for M1 support) + if (rootProject.hasProperty("ndkPath")) { + ndkPath rootProject.ext.ndkPath + } + if (rootProject.hasProperty("ndkVersion")) { + ndkVersion rootProject.ext.ndkVersion } flavorDimensions "vm" diff --git a/template/android/build.gradle b/template/android/build.gradle index 5e77be4eaf4..c6fa898beaa 100644 --- a/template/android/build.gradle +++ b/template/android/build.gradle @@ -6,7 +6,13 @@ buildscript { minSdkVersion = 21 compileSdkVersion = 31 targetSdkVersion = 31 - ndkVersion = "21.4.7075529" + // For M1 Users we need to use the NDK 24, otherwise we default to the + // side-by-side NDK version from AGP. + if (System.properties['os.arch'] == "aarch64") { + ndkVersion = "24.0.8215888" + } else { + ndkVersion = "21.4.7075529" + } } repositories { google()