From fff657a7dac67dfe7e1ba98132bf9fa11a310634 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 12 Jun 2015 19:59:25 -0700 Subject: [PATCH 1/3] Android: Allow NDK location to be overridden --- Source/Android/app/build.gradle | 44 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Source/Android/app/build.gradle b/Source/Android/app/build.gradle index 8f7134c290..c7d41a9082 100644 --- a/Source/Android/app/build.gradle +++ b/Source/Android/app/build.gradle @@ -161,25 +161,33 @@ String getGitPath() { } String getNdkPath() { - try { - def stdout = new ByteArrayOutputStream() - - exec { - // ndk-build.cmd is a file unique to the root directory of android-ndk-r10e. - commandLine 'locate', 'ndk-build.cmd' - standardOutput = stdout - } - - def ndkCmdPath = stdout.toString() - def ndkPath = ndkCmdPath.substring(0, ndkCmdPath.lastIndexOf('/')) - - project.logger.quiet("Gradle: Found Android NDK:" + ndkPath) - - return ndkPath - } catch (ignored) { - project.logger.error("Gradle error: Couldn't find NDK.") - return null; + def propsFile = rootProject.file("build.properties") + def ndkPath = null + if (propsFile.canRead()) { + def buildProperties = new Properties() + buildProperties.load(new FileInputStream(propsFile)) + ndkPath = buildProperties.ndkPath } + if (ndkPath == null) { + try { + def stdout = new ByteArrayOutputStream() + + exec { + // ndk-build.cmd is a file unique to the root directory of android-ndk-r10e. + commandLine 'locate', 'ndk-build.cmd' + standardOutput = stdout + } + + def ndkCmdPath = stdout.toString() + ndkPath = ndkCmdPath.substring(0, ndkCmdPath.lastIndexOf('/')) + } catch (ignored) { + project.logger.error("Gradle error: Couldn't find NDK.") + } + } + if (ndkPath != null) { + project.logger.quiet("Gradle: Found Android NDK: " + ndkPath) + } + return ndkPath } String getAbi() { From 7e36166374c6bf9673d00632b94df4294f002b93 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 13 Jun 2015 03:54:37 -0700 Subject: [PATCH 2/3] Android: Allow git and cmake locations to be overridden --- Source/Android/app/build.gradle | 47 ++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/Source/Android/app/build.gradle b/Source/Android/app/build.gradle index c7d41a9082..6c1a46a914 100644 --- a/Source/Android/app/build.gradle +++ b/Source/Android/app/build.gradle @@ -101,13 +101,13 @@ task setupCMake(type: Exec) { mkdir('build/' + abi) workingDir 'build/' + abi - executable 'cmake' + executable getExecutablePath("cmake") args "-DANDROID=true", "-DANDROID_NATIVE_API_LEVEL=android-18", "-DCMAKE_TOOLCHAIN_FILE=../../../android.toolchain.cmake", "../../../../..", - "-DGIT_EXECUTABLE=" + getGitPath(), + "-DGIT_EXECUTABLE=" + getExecutablePath("git"), "-DANDROID_NDK=" + getNdkPath(), "-DANDROID_TOOLCHAIN_NAME=" + getToolchainName(), "-DANDROID_ABI=" + abi @@ -140,24 +140,33 @@ task compileNative(type: Exec, dependsOn: 'setupCMake') { } } -String getGitPath() { - try { - def stdout = new ByteArrayOutputStream() - - exec { - commandLine 'which', 'git' - standardOutput = stdout - } - - def gitPath = stdout.toString().trim() - project.logger.quiet("Gradle: Found git executuable:" + gitPath) - - return gitPath - } catch (ignored) { - // Shouldn't happen. How did the user get this file without git? - project.logger.error("Gradle error: Couldn't find git executable.") - return null; +String getExecutablePath(String command) { + def propsFile = rootProject.file("build.properties") + def path = null + if (propsFile.canRead()) { + def buildProperties = new Properties() + buildProperties.load(new FileInputStream(propsFile)) + println buildProperties + path = buildProperties[command + "Path"] } + if (path == null) { + try { + def stdout = new ByteArrayOutputStream() + + exec { + commandLine 'which', command + standardOutput = stdout + } + + path = stdout.toString().trim() + } catch (ignored) { + project.logger.error("Gradle error: Couldn't find " + command + " executable.") + } + } + if (path != null) { + project.logger.quiet("Gradle: Found " + command + " executuable:" + path) + } + return path } String getNdkPath() { From dfae4e62669c6effeae949d239e8f1206b0e5360 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 13 Jun 2015 04:04:15 -0700 Subject: [PATCH 3/3] Update Readme with information about more build.properties --- Readme.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 28a78bfbe9..81fe9a38c4 100644 --- a/Readme.md +++ b/Readme.md @@ -63,11 +63,13 @@ following inside: makeArgs= ``` -Replace `` with any arguments you want to pass to `make`, and then execute the -`assembleDebug` or `installDebug` task corresponding to the hardware platform you are targeting. -For example, to deploy to a Nexus 9, which runs the AArch64 architecture, execute `installArm_64Debug`. -A list of available tasks can be found in Android Studio in the Gradle tray, located at the top-right -corner of the IDE by default. +Replace `` with any arguments you want to pass to `make`. If you need to use a specific +version of git, cmake, or the NDK, you can also add `gitPath=`, `cmakePath=` or +`ndkPath=`, replacing `` with the actual paths. Otherwise, these will be found +automatically. Then execute the `assembleDebug` or `installDebug` task corresponding to the +hardware platform you are targeting. For example, to deploy to a Nexus 9, which runs the AArch64 +architecture, execute `installArm_64Debug`. A list of available tasks can be found in Android +Studio in the Gradle tray, located at the top-right corner of the IDE by default. The native libraries will be compiled, and copied into `./Source/Android/app/libs`. Android Studio and Gradle will include any libraries in that folder into the APK at build time.