Hello-Jni on Windows, Android NDK - build-local.mk: No such file
我曾尝试搜寻Internet和StackOverflow(太多文章无法计数),但找不到所有这些方面的帮助:
在Windows上
我是第一次首次涉足Android开发,而我新加入的项目取决于使用NDK进行开发。我一直在阅读NDK随附的文档,但是此示例碰到了一堵石墙。
我正在尝试在NDK中构建示例项目
- Android Studio 1.4(最新,稳定版本当前可用)
- NDK版本:r10e
- 作业系统:Windows 7
Application.mk文件的内容:
1 2 | APP_ABI := all64 // Came with 'all', read somewhere on SO that it // should be 'all64'. Result is the same. |
Android.mk文件的内容:
1 2 3 4 5 6 7 8 | LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello-jni LOCAL_SRC_FILES := hello-jni.c include $(BUILD_SHARED_LIBRARY) |
我的PATH环境变量包括指向我的NDK根文件夹和
1 2 3 4 5 6 7 8 9 | c:\ DK\\android-ndk-r10e\\build\\core\\build-local.mk:40: c:/NDK/android-ndk-r10e/build/core/build/core/init.mk: No such file or directory c:\ DK\\android-ndk-r10e\\build\\core\\build-local.mk:191: \\add-application.mk: No such file or directory c:\ DK\\android-ndk-r10e\\build\\core\\build-local.mk:206: \\setup-imports.mk: No such file or directory c:\ DK\\android-ndk-r10e\\build\\core\\build-local.mk:223: \\build-all.mk: No such file or directory make.exe: *** No rule to make target `\\build-all.mk'. Stop. |
如果人们需要其他帮助我的话,请说"我会提供"。所有帮助将不胜感激。
编辑:
我在Windows上看到的大多数文章都提到Cygwin,但是根据文档,它不是必需的。如果不正确,请纠正我吗?
Windows support
The Windows binaries do not depend on Cygwin. The good news is that they are thus faster, the bad news is that they do not understand the Cygwin path specification like /cygdrive/c/foo/bar (instead of C:/foo/bar).
The NDK build system ensures that all paths passed to the compiler from Cygwin are automatically translated, and deals with other horrors for you. If you have a custom build system, you may need to deal with the problem yourself.
我不能相信这个答案,一位同事好心地帮我解决了这个问题。当他找到答案时,我要求知道他还做了什么,因为显然我一定错过了一些魔术吗?我只看到他在make文件中切换了两行,还需要更多吗? las,不。这就是我的祸根。
由于我不知道NDK如何与Cygwin配合使用,我不愿意在NDK中将其称为错误,但我们都无法理解这种方式对使用本机Windows构建的任何人如何起作用,因为我将参考的代码是记录在git存储库中,是在2011或2010年重新添加的。(https://android.googlesource.com/platform/ndk/+/master/build/core/build-local.mk)
为了帮助说明,这又是我的错误的第一行:
DK\\android-ndk-r10e\\build\\core\\build-local.mk:40: c:/NDK/android-ndk-r10e/build/core/build/core/init.mk: No such file or directory
找不到的第一个文件是
开始构建的命令
1 2 3 4 5 6 7 | NDK_ROOT := $(dir $(lastword $(MAKEFILE_LIST))) NDK_ROOT := $(strip $(NDK_ROOT:%build/core/=%)) NDK_ROOT := $(subst \\,/,$(NDK_ROOT)) NDK_ROOT := $(NDK_ROOT:%/=%) . . . |
第二行从新NDK_ROOT的末尾剥离当前目录的末尾(
哦,但是请看第三行(追溯到2011年)!将替换NDK_ROOT中的每个反斜杠(
剥离调用已经发生,并且如果NDK_ROOT收到带有反斜杠而不是正斜杠的路径,则永远不会找到
1 2 3 4 | NDK_ROOT := $(dir $(lastword $(MAKEFILE_LIST))) NDK_ROOT := $(subst \\,/,$(NDK_ROOT)) NDK_ROOT := $(strip $(NDK_ROOT:%build/core/=%)) NDK_ROOT := $(NDK_ROOT:%/=%) |
现在,我的
我不知道此修补程序是否会破坏Cygwin用户,但我的包装上没有此标签。我也不知道是否会破坏Linux环境,因为我的包装箱中没有Linux。但是,这可能会对Windows的本机用户有所帮助,我希望如此,因为我花了三,四天无休止地挥霍了头,并且阅读了很多SO文章,而不是一次。
在Windows机器上,我遇到此错误,但是却说了clear-vars.mk:没有这样的文件或目录。在查看目录中的ndk-build.cmd之后
C:\\Users\\\\AppData\\Local\\Android\\Sdk\
dk-bundle\\build
该文件看起来像这样
1 2 3 4 5 6 7 | @echo off set NDK_ROOT=%~dp0\\.. set PREBUILT_PATH=%NDK_ROOT%\\prebuilt\\windows-x86_64 if exist %PREBUILT_PATH% goto FOUND set PREBUILT_PATH=%NDK_ROOT%\\prebuilt\\windows :FOUND "%PREBUILT_PATH%\\bin\\make.exe" -f"%NDK_ROOT%\\build\\core\\build-local.mk" SHELL=cmd %* |
但是您还会在目录下找到相同的文件名
C:\\Users\\jmatthews\\AppData\\Local\\Android\\Sdk\
dk-bundle
文件看起来像这样
1 2 3 | @echo off %~dp0\\build\ dk-build.cmd %* |
删除第二行,这样看起来只有1行回声关闭
1 | @echo off |
该文件被调用并弄乱了Windows目录结构。之后,我可以在Windows上进行编译。我在目录中使用空格时项目也遇到问题,因此将项目位置移动到没有空格的目录中。