Android NDK 构建,方法无法解析 [英] Android NDK build, Method could not be resolved

查看:31
本文介绍了Android NDK 构建,方法无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有本机代码的 Android 项目.我可以通过调用 ndk-build 命令从命令行构建本机代码,没有错误或警告.但是当我在 ADT 中打开它时,它显示以下错误.

I have an Android project with native code. I'm able to build native code from command line by calling ndk-build command with no errors or warnings. But when I open it in ADT it shows the following error.

错误信息:Method CallStaticIntMethod 无法解析. 项目中有很多类似错误的文件.

Error message: Method CallStaticIntMethod could not be resolved. There are many files with similar errors in the project.

我仔细检查了配置,这就是我所拥有的.Android 构建、工具链和包含已正确配置(见下图)

I double checked configuration and here is what I have. Android build, tool chain and includes are properly configured (see pictures below)

所需的包含在项目资源管理器中也可见并且它们是有效的(非空且指向正确的头文件).

Required includes are also visible in the Project Explorer and they are valid (not empty and point to correct header files).

但是当我Clean 项目和Build 时,错误仍然存​​在.关于如何解决这个问题的任何想法?

But when I Clean the project and Build it, the errors are still there. Any ideas on how to solve this?

配置:ADT 22.6.2、NDK r9d(64 位)、OSX 10.9.2

Configuration: ADT 22.6.2, NDK r9d (64-bit), OSX 10.9.2

推荐答案

经过一些偏好的挣扎,我终于找到了解决方案.这是 NDK 插件中报告给 AOSP 的错误但尚未修复.评论#50 中描述了答案的过去.这是对我有用的序列.

After some struggling with preferences, I finally found a solution. This is a bug in NDK plugin which was reported to AOSP but not yet fixed. A past of the answer is described in comment #50. Here is the sequence which worked our for me.

  1. 打开项目属性 -> C/C++ Build -> Tool Chan Editor
  2. Used Tools 部分中,将 Android GCC Compiler 替换为 GCC C Compiler.如果部分为空,只需在其中添加 GCC C Compiler 条目.
  3. Open Project Properties -> C/C++ General -> Paths and Symbols 并添加目录,您的 h 文件所在的位置被包括在内.使用 Move up 按钮首先添加一个包含本地包含的文件夹(在我的例子中是 /AudioPlayer/jni).然后添加平台和工具链包括.内置包含应该留在最底部.在我的情况下,工具链包含的完整路径如下所示.这些是原始 Android GCC Compiler 工具链的内置路径,我们已在第 2 步替换.

  1. Open Project Properties -> C/C++ Build -> Tool Chan Editor
  2. In the section Used Tools replace Android GCC Compiler with GCC C Compiler. If section is empty, just add GCC C Compiler entry in there.
  3. Open Project Properties -> C/C++ General -> Paths and Symbols and add directories, where your h-files to be included are located. Use Move up button to add a folder with your local includes (/AudioPlayer/jni in my case) to the first place. Then add platform and toolchains includes. Built-in includes should stay at the very bottom. In my case the full paths to the toolchain includes were like below. These are built-in paths of original Android GCC Compiler toolchain, which we have replaced at step 2.

/Tools/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/include
/Tools/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.6/include-fixed

  • OK按钮,清理重新构建项目.所有错误都必须消失.如果它们仍然存在,请尝试将它们从 问题 视图中删除并重新构建项目.

  • Press OK button, clean and re-build the project. All errors must go away. If they stay, try to remove them from Problems view and re-build project once again.

    更新:我找到了另一个地方,您可以在其中添加路径以包含文件.但是,它似乎与 Eclipse 版本有关.项目设置 -> C/C++ 通用 -> 处理器包含路径、宏等 -> CDT 用户设置条目 -> 添加.添加上面列出的路径后,不再有编译问题.开发又充满乐趣了.

    Update: I have found another place, where you can add paths to include files. However it appears to be Eclipse version dependent. Project Settings -> C/C++ General -> Processor Include Paths, Macros etc. -> CDT User Settings Entries -> Add. After I added the paths listed above, there is no compilation issues anymore. Development is fun again.

    这篇关于Android NDK 构建,方法无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆