Eclipse ADT - 未解决的包含 jni.h

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23122934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 21:39:47  来源:igfitidea点击:

Eclipse ADT - Unresolved inclusion jni.h

androideclipseandroid-ndk

提问by Peter

On my Windows platform, I have the latest version of adt bundle (20140321) and ndk (r9d) installed. The installation is as clean as it gets. The environment variables NDK_ROOT, PATH, etc. are all defined properly.

在我的 Windows 平台上,我安装了最新版本的 adt bundle (20140321) 和 ndk (r9d)。安装非常干净。环境变量 NDK_ROOT、PATH 等都定义正确。

The app I am working on has some C++ native code. The code builds fine both outside Eclipse as well as within Eclipse.

我正在开发的应用程序有一些 C++ 本机代码。代码在 Eclipse 外部和 Eclipse 内部都可以很好地构建。

The problem, however, is that the editor complains that jni.h is an unresolved inclusion.

然而,问题是编辑器抱怨 jni.h 是一个未解决的包含。

Project-->Properties-->C/C++ General-->PathsAndSymbols shows include directories and one of the directories is C:\adt\ndk\platforms\android-19\arch-arm\usr\include. I have verified that jni.h is present in this directory.

Project-->Properties-->C/C++ General-->PathsAndSymbols显示包含目录,其中一个目录是C:\adt\ndk\platforms\android-19\arch-arm\usr\include。我已经验证 jni.h 存在于这个目录中。

I have already checked all other messages on this forum but couldn't find any concrete steps. Appreciate your guidance. Regards.

我已经检查了该论坛上的所有其他消息,但找不到任何具体步骤。感谢您的指导。问候。

回答by bleater

I ran into a similar problem with a working project with Android NDK-based code after updating to Eclipse Kepler. I observed similar things: the header files would correctly be listed under "includes" in the project, the actual build (via ndk-build) worked fine, but Eclipse's editor couldn't locate any headers in standard system directories (all headers with < > brackets).

更新到 Eclipse Kepler 后,我在使用基于 Android NDK 的代码的工作项目中遇到了类似的问题。我观察到类似的事情:头文件会正确地列在项目的“包含”下,实际构建(通过 ndk-build)工作正常,但 Eclipse 的编辑器无法在标准系统目录中找到任何头文件(所有带有 < > 括号)。

I tried many different fixes, including switching toolsets, rebuilding indices etc. without success.

我尝试了许多不同的修复,包括切换工具集、重建索引等,但都没有成功。

Finally, I removed the C nature entirely from the project, and added it back via the "Android Tools" menu in Eclipse.

最后,我从项目中完全删除了 C 特性,并通过 Eclipse 中的“Android 工具”菜单将其添加回来。

Removing the C nature:

删除 C 性质:

The only way I could find to reliably removed the C nature from the project was by hand editing Eclipse's .projectfile for the project.

我能找到的从项目中可靠地删除 C 特性的唯一方法是手动编辑项目的 Eclipse.project文件。

  1. Close the Eclipse project (e.g. by quitting Eclipse).

  2. Open the .projectfile in a text or xml editor. There will be at least 2 <buildCommand>nodes that need to be removed. Remove the <buildCommand>node with name org.eclipse.cdt.managedbuilder.core.genmakebuilderand all its children, and the <buildCommand>node with name org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilderand its children. Finally, remove the lines:

    <nature>org.eclipse.cdt.core.cnature</nature><nature>org.eclipse.cdt.core.ccnature</nature><nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature><nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>

  3. Completely remove the .cprojectfile.

  1. 关闭 Eclipse 项目(例如通过退出 Eclipse)。

  2. .project在文本或 xml 编辑器中打开文件。至少有 2 个<buildCommand>节点需要删除。删除<buildCommand>具有名称的节点org.eclipse.cdt.managedbuilder.core.genmakebuilder及其所有子<buildCommand>节点,以及具有名称的节点org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder及其子节点。最后,删除行:

    <nature>org.eclipse.cdt.core.cnature</nature><nature>org.eclipse.cdt.core.ccnature</nature><nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature><nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>

  3. 彻底删除.cproject文件。

Adding back the Android Native nature

添加回 Android Native 的特性

Reopen the project in Eclipse. Then right-click on the project in the Project Explorer, and from the "Android Tools" contextual menu, choose "Add Native Support...".

在 Eclipse 中重新打开项目。然后在项目资源管理器中右键单击该项目,并从“Android 工具”上下文菜单中选择“添加本机支持...”。

Android Tools ->Add Native Support...

Android 工具 ->添加本机支持...

Looking at the changes made in the .project and .cproject files before and after this change, it appears that it primarily gave new version numbers to the Android NDK tools. In any case, it solved the issue for me.

查看此更改前后在 .project 和 .cproject 文件中所做的更改,似乎它主要为 Android NDK 工具提供了新版本号。无论如何,它为我解决了这个问题。

回答by Jianxing Fan

after add native support,right click project, add includes in c/c++ general--> paths and symbols >> includes, for example add include as %NDK_HOME%\platforms\android-19\arch-arm\usr\include

添加原生支持后,右键项目,在c/c++通用中添加includes-->路径和符号>>includes,例如添加include为%NDK_HOME%\platforms\android-19\arch-arm\usr\include

回答by Pau Guillamon

I had the same problem some days ago. I found a fix in another question here in stackoverflow, but now I can't find the link.

几天前我遇到了同样的问题。我在 stackoverflow 的另一个问题中找到了解决方法,但现在找不到链接。

In Eclipse: right-click on your project > Properties > C/C++ General > Code Analysis > Launching and disable both options ("Run with build" and "Run as you type").

在 Eclipse 中:右键单击您的项目 > 属性 > C/C++ 常规 > 代码分析 > 启动并禁用这两个选项(“Run with build”和“Run as you type”)。

There seems to be a problem with CDT and the Indexer, doing this you hide the problem. The editor will still complain but now you should be able to run and debug your application.

CDT 和索引器似乎有问题,这样做可以隐藏问题。编辑器仍然会抱怨,但现在您应该能够运行和调试您的应用程序。

回答by Playful Curiosity

I solved this for adt-bundle-windows-x86_64-20140321:

我为 adt-bundle-windows-x86_64-20140321 解决了这个问题:

  1. No any environment variables is set, just pointed NDK location under Preferences > Android > NDK.
  2. I created new, clean Eclipse workspace.
  3. Deleted from my project with C++ code next files/folders:
  1. 没有设置任何环境变量,只是在 Preferences > Android > NDK 下指向 NDK 位置。
  2. 我创建了新的、干净的 Eclipse 工作区。
  3. 使用 C++ 代码从我的项目中删除下一个文件/文件夹:

.settings
.classpath
.cproject
.project
project.properties

.settings
.classpath
.cproject
.project
project.properties

  1. Eclipse > New > Other > Android > Android Project from Existing Code > then point folder with your project, let Eclipse detect it, check "Copy project into workspace" and click Ok/Next, whatever.
  2. Clean project.
  3. Right click on project > Android Tools > Add native support
  4. Rebuild, possibly restart workspace.
  1. Eclipse > New > Other > Android > Android Project from Existing Code > 然后将文件夹指向您的项目,让 Eclipse 检测到它,选中“Copy project into workspace”,然后单击 Ok/Next,无论如何。
  2. 清洁项目。
  3. 右键单击项目> Android 工具> 添加本机支持
  4. 重建,可能重新启动工作区。

Also this solved issue with Eclipse 4.3 previously ignored build system and user defined compiler flags. Now macros folding dependent on this flags etc works fine.

这也解决了 Eclipse 4.3 之前忽略的构建系统和用户定义的编译器标志的问题。现在依赖于这个标志等的宏折叠工作正常。

If more general - NDK plugin can properly define for you right includes and anything other required to work fine, but you need to clean your project from broken crap.

如果更通用 - NDK 插件可以为您正确定义正确的包含和任何其他正常工作所需的内容,但您需要从破碎的垃圾中清理您的项目。