系统找不到指定的路径
在执行项目构建时,遇到了系统提示找不到指定路径的问题,以下是详细的错误信息及解决方案。
错误信息
在命令行执行如下命令时:
F:\\cocos2d-x-3.2\\tools\\cocos2d-console\\bin\\HelloCpp\\proj.android>python build_native.py
输出如下信息:
The Selected NDK toolchain version was 4.8 !
系统找不到指定的路径。
Traceback (most recent call last):
File “build_native.py”, line 159, in
build(opts.ndk_build_param,opts.android_platform,opts.build_mode)
File “build_native.py”, line 146, in build
do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
File “build_native.py”, line 82, in do_build
raise Exception(“Build dynamic library for project [ ” + app_android_root + ” ] fails!”)
Exception: Build dynamic library for project [ F:\\cocos2d-x-3.2\\tools\\cocos2d-console\\bin\\HelloCpp\\proj.android ] fails!
从错误信息可以看出,在执行 python build_native.py 脚本时,系统找不到指定的路径,最终导致项目动态库构建失败。
解决方案
该问题可能是由于环境变量 NDK_ROOT 未正确配置引起的。以下是一个检查环境变量 NDK_ROOT 的 Python 函数:
import sys
def check_environment_variables():
"""
Checking the environment NDK_ROOT, which will be used for building
"""
try:
# 这里改成你 NDK 的绝对路径
NDK_ROOT = "/Users/android/android-ndk-r9d"
except Exception:
print("NDK_ROOT not defined. Please define NDK_ROOT in your environment")
sys.exit(1)
return NDK_ROOT
代码解释
- 函数功能:
check_environment_variables函数用于检查并获取环境变量NDK_ROOT的值。 - 异常处理:如果无法获取
NDK_ROOT的值,程序将输出错误信息并退出。 - 路径设置:你需要将代码中的
"/Users/android/android-ndk-r9d"替换为你本地 NDK 的绝对路径。
通过正确配置 NDK_ROOT 环境变量,应该可以解决系统找不到指定路径的问题。