我有一个Android Studio项目,它无法识别ndk-build的PATH变量集。
如果我从终端I运行ndk-build
,请:
stpns-MacBook-Pro:~ stepanboltalin$ ndk-build
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/usr/local/Cellar/android-ndk/r10b/build/core/build-local.mk:148: *** Android NDK: Aborting . Stop.
但是如果我尝试在Android Studio中编译项目,我会在'ndk-build'commandLine上得到错误(下面是build.gradle的摘录:
task ndkBuild(type: Exec) {
# some stuff...
if (ant.properties.os == 'windows') {
commandLine 'ndk-build.cmd'
} else {
commandLine 'ndk-build'
}
}
现在,如果我添加绝对路径,一切正常:
task ndkBuild(type: Exec) {
# some stuff...
if (ant.properties.os == 'windows') {
commandLine 'ndk-build.cmd'
} else {
commandLine '/usr/local/opt/ndk-build'
}
}
虽然这个问题似乎已经解决了,但像这样的build.gradle对于开发来说是次优的。我怎样才能解决这个问题?
答案 0 :(得分:5)
您可以在根项目的local.properties文件中添加NDK的路径:
ndk.dir=/opt/android/ndk
然后像这样替换ndk-build的调用:
def localProperties = new Properties()
localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = localProperties.getProperty('ndk.dir')
def ndkBuildPrefix = ndkDir != null ? ndkDir + '/' : '';
if (ant.properties.os == 'windows') {
commandLine ndkBuildPrefix + 'ndk-build.cmd'
} else {
commandLine ndkBuildPrefix + 'ndk-build'
}