Skip to content

Commit 6268836

Browse files
cortinicofortmarek
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 9efcaff commit 6268836

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

ReactAndroid/build.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,13 @@ task androidSourcesJar(type: Jar) {
281281
android {
282282
compileSdkVersion 31
283283

284-
// Used to override the NDK path & version on internal CI
285-
if (System.getenv("ANDROID_NDK") != null && System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) {
286-
ndkPath System.getenv("ANDROID_NDK")
287-
ndkVersion System.getenv("LOCAL_ANDROID_NDK_VERSION")
284+
// Used to override the NDK path/version on internal CI or by allowing
285+
// users to customize the NDK path/version from their root project (e.g. for M1 support)
286+
if (rootProject.hasProperty("ndkPath")) {
287+
ndkPath rootProject.ext.ndkPath
288+
}
289+
if (rootProject.hasProperty("ndkVersion")) {
290+
ndkVersion rootProject.ext.ndkVersion
288291
}
289292

290293
defaultConfig {

build.gradle.kts

Lines changed: 3 additions & 0 deletions
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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,13 @@ def reactNativeArchitectures() {
145145
android {
146146
compileSdkVersion 31
147147

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

154157
flavorDimensions "vm"

template/android/build.gradle

Lines changed: 7 additions & 1 deletion
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)