Skip to content

Commit 477f546

Browse files
cortinicofacebook-github-bot
authored andcommitted
Bump CMake to 3.22.1 to properly honor CMAKE_BUILD_TYPE (#35857)
Summary: Pull Request resolved: #35857 It seems like there is an incompatibility between NDK 23 (shipped in 0.71) and the usage of custom `CMAKE_BUILD_TYPE` we do for Hermes. Specifically the `-DCMAKE_BUILD_TYPE=Release` we specify for the debug variant of Hermes is partially ignored by the new Android native build toolchain. See android/ndk#463 for mentions on how the toolchains requires CMake 3.20+ As AGP 7.3 defaults to use CMake 3.18 unless specified, and NDK 23 unless specified. AGP 7.4 defaults to use CMake 3.22 unless specified, and NDK 23 unless specified. See: https://developer.android.com/studio/releases/gradle-plugin#7-4-0 Here I'm: 1. Bumping the docker image to an image that contains the CMake 3.22 2. Updating the logic for building `react-native` & `hermes-engine` to use 3.22 3. Provide fallbacks if the user specified `CMAKE_VERSION` Template tests will run on AGP 7.3 and will still use CMake 3.18, but I forecast no problem there as the user is not supposed to specify custom `CMAKE_BUILD_TYPE`. This is only a problem as we build `hermes-engine` with custom build types. Changelog: [Android] [Fixed] - Bump CMake to 3.22.1 to properly honor CMAKE_BUILD_TYPE Reviewed By: cipolleschi Differential Revision: D42544864 fbshipit-source-id: efd0f51120370fb808337c201df31d71f4ddfdbc
1 parent f238f15 commit 477f546

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

.circleci/Dockerfiles/Dockerfile.android

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# and build a Android application that can be used to run the
1515
# tests specified in the scripts/ directory.
1616
#
17-
FROM reactnativecommunity/react-native-android:6.1
17+
FROM reactnativecommunity/react-native-android:6.2
1818

1919
LABEL Description="React Native Android Test Image"
2020
LABEL maintainer="Héctor Ramos <[email protected]>"

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ executors:
115115
reactnativeandroid:
116116
<<: *defaults
117117
docker:
118-
- image: reactnativecommunity/react-native-android:6.1
118+
- image: reactnativecommunity/react-native-android:6.2
119119
resource_class: "xlarge"
120120
environment:
121121
- TERM: "dumb"

ReactAndroid/build.gradle

+11-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File(
3939
def thirdPartyNdkDir = new File("$buildDir/third-party-ndk")
4040
def reactNativeRootDir = projectDir.parent
4141

42+
// We put the publishing version from gradle.properties inside ext. so other
43+
// subprojects can access it as well.
44+
ext.publishing_version = VERSION_NAME
45+
46+
// This is the version of CMake we're requesting to the Android SDK to use.
47+
// If missing it will be downloaded automatically. Only CMake versions shipped with the
48+
// Android SDK are supported (you can find them listed in the SDK Manager of Android Studio).
49+
def cmakeVersion = System.getenv("CMAKE_VERSION") ?: "3.22.1"
50+
ext.cmake_version = cmakeVersion
51+
4252
// You need to have following folders in this directory:
4353
// - boost_1_76_0
4454
// - double-conversion-1.1.6
@@ -224,10 +234,6 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa
224234
it.outputDir.set(prefabHeadersDir)
225235
}
226236

227-
// We put the publishing version from gradle.properties inside ext. so other
228-
// subprojects can access it as well.
229-
ext.publishing_version = VERSION_NAME
230-
231237
task createNativeDepsDirectories {
232238
downloadsDir.mkdirs()
233239
thirdPartyNdkDir.mkdirs()
@@ -487,6 +493,7 @@ android {
487493

488494
externalNativeBuild {
489495
cmake {
496+
version cmakeVersion
490497
path "src/main/jni/CMakeLists.txt"
491498
}
492499
}

ReactAndroid/hermes-engine/build.gradle

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ plugins {
1616

1717
group = "com.facebook.react"
1818
version = parent.publishing_version
19+
def cmakeVersion = parent.cmake_version
1920

20-
def cmakeVersion = "3.18.1"
2121
/**
2222
* We use the bundled version of CMake in the Android SDK if available, to don't force Android
2323
* users to install CMake externally.
2424
*/
2525
def findCmakePath(cmakeVersion) {
26-
if (System.getenv("ANDROID_SDK_ROOT")) {
27-
return "${System.getenv("ANDROID_SDK_ROOT")}/cmake/${cmakeVersion}/bin/cmake"
26+
def cmakeRelativePath = "/cmake/${cmakeVersion}/bin/cmake"
27+
if (System.getenv("ANDROID_SDK_ROOT") && new File("${System.getenv("ANDROID_SDK_ROOT")}/${cmakeRelativePath}").exists()) {
28+
return "${System.getenv("ANDROID_SDK_ROOT")}/${cmakeRelativePath}"
2829
}
29-
if (System.getenv("ANDROID_HOME")) {
30-
return "${System.getenv("ANDROID_HOME")}/cmake/${cmakeVersion}/bin/cmake"
30+
if (System.getenv("ANDROID_HOME") && new File("${System.getenv("ANDROID_HOME")}/${cmakeRelativePath}").exists()) {
31+
return "${System.getenv("ANDROID_HOME")}/${cmakeRelativePath}"
3132
}
3233
return "cmake"
3334
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"prettier": "prettier --write \"./**/*.{js,md,yml,ts,tsx}\"",
8686
"format-check": "prettier --list-different \"./**/*.{js,md,yml,ts,tsx}\"",
8787
"update-lock": "npx yarn-deduplicate",
88-
"docker-setup-android": "docker pull reactnativecommunity/react-native-android:6.1",
88+
"docker-setup-android": "docker pull reactnativecommunity/react-native-android:6.2",
8989
"docker-build-android": "docker build -t reactnativeci/android -f .circleci/Dockerfiles/Dockerfile.android .",
9090
"test-android-run-instrumentation": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-instrumentation-tests.sh",
9191
"test-android-run-unit": "docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-unit-tests.sh",

0 commit comments

Comments
 (0)