From 5b34c98fa21d592c02c0fee7a7d67fe080233fdf Mon Sep 17 00:00:00 2001 From: Agastya Darma Date: Mon, 4 Jan 2021 09:12:53 -0800 Subject: [PATCH] WIP: Add an explicit NDK version to RNTester and ReactAndroid (#29987) Summary: When I try to run RNTester with Gradle the RNTester Required me to use **NDK 20.0.5594570**. I can't seem to find an explicit NDK version anywhere in ReactAndroid and RNTester. This PR Aims to add an explicit NDK version to RNTester and ReactAndroid. ![Screenshot from 2020-09-19 21-13-17](https://user-images.githubusercontent.com/8868908/93669563-444fcf00-fabf-11ea-8822-93264c5bb736.png) ## Changelog [Android] [Added] - Add an explicit NDK version to RNTester and ReactAndroid. Pull Request resolved: https://github.com/facebook/react-native/pull/29987 Test Plan: Build manually from RNTester Reviewed By: fkgozali Differential Revision: D23911371 Pulled By: ShikaSD fbshipit-source-id: 2f297c73890c0eb0bfec0e2ba7ec5755b4d84243 --- .circleci/config.yml | 4 ++-- ReactAndroid/build.gradle | 18 ++++++++++-------- build.gradle.kts | 5 +++++ gradle.properties | 2 ++ packages/rn-tester/android/app/build.gradle | 2 +- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 025669fdb324ff..49c0c6603f4051 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -611,11 +611,11 @@ jobs: default: false environment: - ANDROID_HOME: "C:\\Android\\android-sdk" - - ANDROID_NDK: "C:\\Android\\android-sdk\\ndk\\19.2.5345600" + - ANDROID_NDK: "C:\\Android\\android-sdk\\ndk\\20.1.5948944" - ANDROID_BUILD_VERSION: 28 - ANDROID_TOOLS_VERSION: 29.0.3 - GRADLE_OPTS: -Dorg.gradle.daemon=false - - NDK_VERSION: 19.2.5345600 + - NDK_VERSION: 20.1.5948944 steps: - checkout diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 3b3f973ade27a0..1ed98bed6eb40b 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -242,26 +242,28 @@ def getNdkBuildName() { } def findNdkBuildFullPath() { + // android.ndkDirectory should return project.android.ndkVersion ndkDirectory + def ndkDir = android.ndkDirectory ? android.ndkDirectory.absolutePath : null + if (ndkDir) { + return new File(ndkDir, getNdkBuildName()).getAbsolutePath() + } + // we allow to provide full path to ndk-build tool if (hasProperty("ndk.command")) { return property("ndk.command") } // or just a path to the containing directory if (hasProperty("ndk.path")) { - def ndkDir = property("ndk.path") + ndkDir = property("ndk.path") return new File(ndkDir, getNdkBuildName()).getAbsolutePath() } + // @TODO ANDROID_NDK && ndk.dir is deprecated and will be removed in the future. if (System.getenv("ANDROID_NDK") != null) { - def ndkDir = System.getenv("ANDROID_NDK") + ndkDir = System.getenv("ANDROID_NDK") return new File(ndkDir, getNdkBuildName()).getAbsolutePath() } - def ndkDir = android.ndkDirectory ? android.ndkDirectory.absolutePath : null - - if (ndkDir) { - return new File(ndkDir, getNdkBuildName()).getAbsolutePath() - } return null } @@ -377,7 +379,7 @@ task extractJNIFiles { android { compileSdkVersion 29 - + ndkVersion ANDROID_NDK_VERSION compileOptions { sourceCompatibility(JavaVersion.VERSION_1_8) targetCompatibility(JavaVersion.VERSION_1_8) diff --git a/build.gradle.kts b/build.gradle.kts index 4d2c53b0189eb3..532c996c131dc4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,4 +34,9 @@ allprojects { google() jcenter() } + + // used to override ndk path on CI + if (System.getenv("LOCAL_ANDROID_NDK_VERSION") != null) { + setProperty("ANDROID_NDK_VERSION", System.getenv("LOCAL_ANDROID_NDK_VERSION")) + } } diff --git a/gradle.properties b/gradle.properties index f0a3fdf5d79fed..dd6698ad75bd27 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,3 +3,5 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.parallel=true + +ANDROID_NDK_VERSION=20.1.5948944 diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 8855fff3fd2b9c..59a2e64275a35c 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -127,7 +127,7 @@ def useIntlJsc = false android { compileSdkVersion 29 - + ndkVersion ANDROID_NDK_VERSION compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8