Path变量Android Studio中(NDK-build命令无法识别)无法识别 [英] Path variable not recognized in Android Studio (ndk-build command is not recognized)
问题描述
我有将无法识别PATH变量NDK的构建设置一个Android Studio项目。
I have an Android Studio project which won't recognize the PATH variable set for ndk-build.
如果我跑 NDK的构建
从终端获取:
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的构建commmandLine(得到错误下面是对的build.gradle摘录:
But if I try to compile project in Android Studio, I get error at 'ndk-build' commmandLine (below is the excerpt from build.gradle:
task ndkBuild(type: Exec) {
# some stuff...
if (ant.properties.os == 'windows') {
commandLine 'ndk-build.cmd'
} else {
commandLine 'ndk-build'
}
}
现在如果我添加的绝对路径,一切工作正常:
Now if I add the absolute path everything works fine:
task ndkBuild(type: Exec) {
# some stuff...
if (ant.properties.os == 'windows') {
commandLine 'ndk-build.cmd'
} else {
commandLine '/usr/local/opt/ndk-build'
}
}
虽然问题似乎解决了,具有的build.gradle喜欢就是次最佳的发展。我该如何解决这个问题?
Although the problem is seemingly solved, having build.gradle like that is sub-optimal for development. How can I fix this?
推荐答案
您可以在路径中的根项目的local.properties文件添加到您的NDK:
You can add the path to your NDK in the local.properties file of the root project:
ndk.dir=/opt/android/ndk
然后替换的调用NDK,建立这样的:
Then replace the invocation of ndk-build like this:
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'
}
这篇关于Path变量Android Studio中(NDK-build命令无法识别)无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!