Skip to content

Commit 4befd2a

Browse files
cortinicofacebook-github-bot
authored andcommitted
Improve support for Android users on M1 machine (#33588)
Summary: Pull Request resolved: #33588 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 Reviewed By: mdvacca Differential Revision: D35468252 fbshipit-source-id: b73f5262b9408f04f3ae4fd26458a4d17c1ec29a
1 parent e89c93f commit 4befd2a

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

ReactAndroid/build.gradle

+7-4
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,13 @@ android {
252252
buildToolsVersion = "31.0.0"
253253
compileSdkVersion 31
254254

255-
// Used to override the NDK path & version on internal CI
256-
if (System.getenv("ANDROID_NDK") != null && System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) {
257-
ndkPath System.getenv("ANDROID_NDK")
258-
ndkVersion System.getenv("LOCAL_ANDROID_NDK_VERSION")
255+
// Used to override the NDK path/version on internal CI or by allowing
256+
// users to customize the NDK path/version from their root project (e.g. for M1 support)
257+
if (rootProject.hasProperty("ndkPath")) {
258+
ndkPath rootProject.ext.ndkPath
259+
}
260+
if (rootProject.hasProperty("ndkVersion")) {
261+
ndkVersion rootProject.ext.ndkVersion
259262
}
260263

261264
defaultConfig {

build.gradle.kts

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
val ndkPath by extra(System.getenv("ANDROID_NDK"))
9+
val ndkVersion by extra(System.getenv("ANDROID_NDK_VERSION"))
10+
811
buildscript {
912
repositories {
1013
google()

packages/rn-tester/android/app/build.gradle

+7-4
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,13 @@ android {
146146
buildToolsVersion = "31.0.0"
147147
compileSdkVersion 31
148148

149-
// Used to override the NDK path & version on internal CI
150-
if (System.getenv("ANDROID_NDK") != null && System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) {
151-
ndkPath System.getenv("ANDROID_NDK")
152-
ndkVersion System.getenv("LOCAL_ANDROID_NDK_VERSION")
149+
// Used to override the NDK path/version on internal CI or by allowing
150+
// users to customize the NDK path/version from their root project (e.g. for M1 support)
151+
if (rootProject.hasProperty("ndkPath")) {
152+
ndkPath rootProject.ext.ndkPath
153+
}
154+
if (rootProject.hasProperty("ndkVersion")) {
155+
ndkVersion rootProject.ext.ndkVersion
153156
}
154157

155158
flavorDimensions "vm"

template/android/build.gradle

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ buildscript {
66
minSdkVersion = 21
77
compileSdkVersion = 31
88
targetSdkVersion = 31
9-
ndkVersion = "21.4.7075529"
9+
// For M1 Users we need to use the NDK 24, otherwise we default to the
10+
// side-by-side NDK version from AGP.
11+
if (System.properties['os.arch'] == "aarch64") {
12+
ndkVersion = "24.0.8215888"
13+
} else {
14+
ndkVersion = "21.4.7075529"
15+
}
1016
}
1117
repositories {
1218
google()

0 commit comments

Comments
 (0)