Merge pull request #2597 from endrift/android-allow-ndk-override

Android: Allow NDK location to be specified manually
This commit is contained in:
Ryan Houdek 2015-06-13 13:56:53 -05:00
commit c981f6407e
2 changed files with 61 additions and 42 deletions

View file

@ -63,11 +63,13 @@ following inside:
makeArgs=<make-args> makeArgs=<make-args>
``` ```
Replace `<make-args>` with any arguments you want to pass to `make`, and then execute the Replace `<make-args>` with any arguments you want to pass to `make`. If you need to use a specific
`assembleDebug` or `installDebug` task corresponding to the hardware platform you are targeting. version of git, cmake, or the NDK, you can also add `gitPath=<path>`, `cmakePath=<path>` or
For example, to deploy to a Nexus 9, which runs the AArch64 architecture, execute `installArm_64Debug`. `ndkPath=<path>`, replacing `<path>` with the actual paths. Otherwise, these will be found
A list of available tasks can be found in Android Studio in the Gradle tray, located at the top-right automatically. Then execute the `assembleDebug` or `installDebug` task corresponding to the
corner of the IDE by default. 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 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. and Gradle will include any libraries in that folder into the APK at build time.

View file

@ -101,13 +101,13 @@ task setupCMake(type: Exec) {
mkdir('build/' + abi) mkdir('build/' + abi)
workingDir 'build/' + abi workingDir 'build/' + abi
executable 'cmake' executable getExecutablePath("cmake")
args "-DANDROID=true", args "-DANDROID=true",
"-DANDROID_NATIVE_API_LEVEL=android-18", "-DANDROID_NATIVE_API_LEVEL=android-18",
"-DCMAKE_TOOLCHAIN_FILE=../../../android.toolchain.cmake", "-DCMAKE_TOOLCHAIN_FILE=../../../android.toolchain.cmake",
"../../../../..", "../../../../..",
"-DGIT_EXECUTABLE=" + getGitPath(), "-DGIT_EXECUTABLE=" + getExecutablePath("git"),
"-DANDROID_NDK=" + getNdkPath(), "-DANDROID_NDK=" + getNdkPath(),
"-DANDROID_TOOLCHAIN_NAME=" + getToolchainName(), "-DANDROID_TOOLCHAIN_NAME=" + getToolchainName(),
"-DANDROID_ABI=" + abi "-DANDROID_ABI=" + abi
@ -140,46 +140,63 @@ task compileNative(type: Exec, dependsOn: 'setupCMake') {
} }
} }
String getGitPath() { String getExecutablePath(String command) {
try { def propsFile = rootProject.file("build.properties")
def stdout = new ByteArrayOutputStream() def path = null
if (propsFile.canRead()) {
exec { def buildProperties = new Properties()
commandLine 'which', 'git' buildProperties.load(new FileInputStream(propsFile))
standardOutput = stdout println buildProperties
} path = buildProperties[command + "Path"]
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;
} }
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() { String getNdkPath() {
try { def propsFile = rootProject.file("build.properties")
def stdout = new ByteArrayOutputStream() def ndkPath = null
if (propsFile.canRead()) {
exec { def buildProperties = new Properties()
// ndk-build.cmd is a file unique to the root directory of android-ndk-r10e. buildProperties.load(new FileInputStream(propsFile))
commandLine 'locate', 'ndk-build.cmd' ndkPath = buildProperties.ndkPath
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;
} }
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() { String getAbi() {