eclipse 类型 'jint' 无法解析,并且 JNIEnv、jclass
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11666711/
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
Type 'jint' could not be resolved, and JNIEnv, jclass
提问by Gatica
Trying to build a simple helloWorld android/java application with jni c code. I am using Eclipse Indigo on Windows 7. Installed ndk r8 in a non-space path, have the c library finally building fine with ndk-build.cmd. However, the header file generated by javah has unresolved errors,
尝试使用 jni c 代码构建一个简单的 helloWorld android/java 应用程序。我在 Windows 7 上使用 Eclipse Indigo。在非空间路径中安装了 ndk r8,最终使用 ndk-build.cmd 构建了 c 库。但是javah生成的头文件有未解决的错误,
- Type 'jint' could not be resolved
- Type 'JNIEnv' could not be resolved
- Type 'jclass' could not be resolved
- 无法解析类型“jint”
- 无法解析类型“JNIEnv”
- 无法解析类型“jclass”
It wasn't seeing the jni.h include yesterday but after a reboot this morning, that error has disappeared. I had an unresolved JNIEXPORT and JNICALL error as well, but #defining them seems to have solved that. Stuck on the last 3 above. Have searched google and Stack Overflow for answers but as soon as someone finds a solution they don't say what that solution was :(
昨天没有看到 jni.h 包含在内,但今天早上重新启动后,该错误消失了。我也有一个未解决的 JNIEXPORT 和 JNICALL 错误,但 #defining 它们似乎已经解决了这个问题。卡在上面的最后 3 个。已经在 google 和 Stack Overflow 上搜索了答案,但是一旦有人找到解决方案,他们就不会说该解决方案是什么:(
I've checked the includes in java and c/c++ perspectives in project properties. It seems to be including jni.h directories that I want, I'm using the android-14 for arm platforms. The target is a 4.0.3 IceCream Sanwich (which confusingly is API 15?!). I was going to try and use an AVD for testing this. I've tried closing/reopening the project, deleting from Eclipse and reimporting, but none of that has worked.
我已经检查了项目属性中的 java 和 c/c++ 透视图中的包含。它似乎包括我想要的 jni.h 目录,我将 android-14 用于 arm 平台。目标是 4.0.3 IceCream Sanwich(令人困惑的是 API 15?!)。我打算尝试使用 AVD 来测试这个。我试过关闭/重新打开项目,从 Eclipse 中删除并重新导入,但这些都没有奏效。
Am I missing some includes? Which ones and where should I set them? Would really appreciate some help.
我错过了一些包括吗?我应该在哪里设置哪些?真的很感激一些帮助。
采纳答案by Yury
Recently I've faced with the same problem. In my case the problem was that I converted my Eclipse project to C++ project, but I had used C type. So to solve this problem I simply deleted the line <nature>org.eclipse.cdt.core.ccnature</nature>
from .project
file from the project directory:
最近我遇到了同样的问题。就我而言,问题是我将 Eclipse 项目转换为 C++ 项目,但我使用了 C 类型。因此,要解决这个问题,我只是删除线<nature>org.eclipse.cdt.core.ccnature</nature>
从.project
从项目目录文件:
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<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>
<nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature>
</natures>
Then restart your Eclipse. For more information you can read this.
然后重新启动 Eclipse。有关更多信息,您可以阅读此内容。
回答by weston
Right click project and go to properties properties.
右键单击项目并转到属性属性。
Go to C/C++ General->Paths and Symbols.
转到C/C++ General->Paths and Symbols。
In Includes->GNU Cadd the equivalent of this:
在Includes->GNU C 中添加与此等效的内容:
%ndkroot%\platforms\android-8\arch-arm\usr\include
%ndkroot%\platforms\android-8\arch-arm\usr\include
You may want to point to other platform versions of the NDK, just change the android-8 part of the path.
您可能希望指向 NDK 的其他平台版本,只需更改路径的 android-8 部分即可。
回答by MscG
Try to add a #undef __cplusplus
just before the #include
directives, like this:
尝试#undef __cplusplus
在#include
指令之前添加一个,如下所示:
#undef __cplusplus
#include <string.h>
#include <jni.h>
This will force Eclipse to consider the non-c++
definitions of the NDK objects.
这将强制 Eclipse 考虑non-c++
NDK 对象的定义。