From 5547df33290676370d250ed4b9433de37a26f558 Mon Sep 17 00:00:00 2001 From: Ashwin Phatak Date: Thu, 24 Aug 2017 16:04:47 +0530 Subject: [PATCH] Check that Android NDK version 10e is being used for the build --- react-native/android/build.gradle | 38 ++++++++++++++++++++++++++ react-native/android/gradle.properties | 1 + 2 files changed, 39 insertions(+) diff --git a/react-native/android/build.gradle b/react-native/android/build.gradle index 01052378..53fceccc 100644 --- a/react-native/android/build.gradle +++ b/react-native/android/build.gradle @@ -137,6 +137,41 @@ def findNdkBuildFullPath() { return null } +def checkNdkVersion(ndkBuildFullPath) { + def ndkPath = new File(ndkBuildFullPath).getParent() + def detectedNdkVersion + def releaseFile = new File(ndkPath, 'RELEASE.TXT') + def propertyFile = new File(ndkPath, 'source.properties') + if (releaseFile.isFile()) { + detectedNdkVersion = releaseFile.text.trim().split()[0].split('-')[0] + } else if (propertyFile.isFile()) { + detectedNdkVersion = getValueFromPropertiesFile(propertyFile, 'Pkg.Revision') + if (detectedNdkVersion == null) { + throw new GradleException("Failed to obtain the NDK version information from ${ndkPath}/source.properties") + } + } else { + throw new GradleException("Neither ${releaseFile.getAbsolutePath()} nor ${propertyFile.getAbsolutePath()} is a file.") + } + if (detectedNdkVersion != project.ndkVersion) { + throw new GradleException("Your NDK version: ${detectedNdkVersion}." + + " Realm JNI must be compiled with the version ${project.ndkVersion} of NDK.") + } +} + +static def getValueFromPropertiesFile(File propFile, String key) { + if (!propFile.isFile() || !propFile.canRead()) { + return null + } + def prop = new Properties() + def reader = propFile.newReader() + try { + prop.load(reader) + } finally { + reader.close() + } + return prop.get(key) +} + def getNdkBuildFullPath() { def ndkBuildFullPath = findNdkBuildFullPath() if (ndkBuildFullPath == null) { @@ -153,6 +188,9 @@ def getNdkBuildFullPath() { "(On Windows, make sure you escape backslashes in local.properties or use forward slashes, e.g. C:\\\\ndk or C:/ndk rather than C:\\ndk)", null) } + + checkNdkVersion(ndkBuildFullPath); + return ndkBuildFullPath } diff --git a/react-native/android/gradle.properties b/react-native/android/gradle.properties index 645750a5..9194dd13 100644 --- a/react-native/android/gradle.properties +++ b/react-native/android/gradle.properties @@ -6,3 +6,4 @@ POM_PACKAGING=aar POM_DESCRIPTION=Android Realm React Native module. Realm is a mobile database: a replacement for SQLite & ORMs DEBUG_BUILD=true android.useDeprecatedNdk=true +ndkVersion=r10e