unresolved inclusion in the java header in JNI

时间:2024-11-13 20:07:32

eclipse的ndk开发环境建差不多后打开jni的samples里的hello-jni项目。添加native和运行都没有问题,但是打开hello-jni.c看到一片红:

unresolved inclusion in the java header in JNI

光这一个文件牵涉的问题有下面一些,罗列出来方便搜到。

Unresolved inclusion: <string.h>

Unresolved inclusion: <jni.h>

Type 'jstring' could not be resolved

Type 'JNIEnv' could not be resolved

Type 'jobject' could not be resolved

还可能有NewStringUTF的Unresoved问题(解决方法在最下面)

原理没研究,解决方法根据情况不同可能涉及到下面的一种或两种方法

方法一,通过重建.project和.cproject解决

来源:http://*.com/questions/23122934/eclipse-adt-unresolved-inclusion-jni-h

1. 关闭eclipse

2. 用notepad++等工具打开hello-jni文件夹中的.project文件,把下面三块内容删除

        <buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
        <buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
        <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. 保存

4. 删除同文件夹下的.cproject文件

5. 重新打开eclipse

6. 右键项目-->Android Tools-->Add Native Support...点击finish

unresolved inclusion in the java header in JNI

如果问题没有解决,

方法二,添加c和c++库的路径

右键项目 --> Properties --> C/C++ General --> Path and Symbols --> Includes 点击右边的Add...按钮添加include路径在ndk路径里,我的是:

D:\XunLeiDownload\android-ndk-r10e\platforms\android-16\arch-arm\usr\include

Refresh项目,问题解决:

unresolved inclusion in the java header in JNI

对于NewStringUTF的Unresoved问题,找了下,不完美的解决方法是 Window --> Preferences --> C/C++ --> Code Analysis里把Method cannot be resolved这个检查项去掉即可。