gpt4 book ai didi

macos - Android Studio 中无法识别路径变量(无法识别 ndk-build 命令)

转载 作者:行者123 更新时间:2023-12-03 16:53:12 27 4
gpt4 key购买 nike

我有一个 Android Studio 项目,它无法识别为 ndk-build 设置的 PATH 变量。

如果我运行 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”命令行中出现错误(以下是 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 对于开发来说并不是最佳选择。我怎样才能解决这个问题?

最佳答案

您可以在根项目的 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'
}

关于macos - Android Studio 中无法识别路径变量(无法识别 ndk-build 命令),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26960891/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com