Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'jint' could not be resolved, and JNIEnv, jclass

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,

  • Type 'jint' could not be resolved
  • Type 'JNIEnv' could not be resolved
  • Type 'jclass' could not be resolved

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 :(

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.

Am I missing some includes? Which ones and where should I set them? Would really appreciate some help.

like image 994
Gatica Avatar asked Jul 26 '12 09:07

Gatica


3 Answers

Right click project and go to properties properties.

Go to C/C++ General->Paths and Symbols.

In Includes->GNU C add the equivalent of this:

%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.

like image 119
weston Avatar answered Oct 09 '22 20:10

weston


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:

<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.

like image 17
Yury Avatar answered Oct 09 '22 20:10

Yury


Try to add a #undef __cplusplus just before the #include directives, like this:

#undef __cplusplus
#include <string.h>
#include <jni.h>

This will force Eclipse to consider the non-c++ definitions of the NDK objects.

like image 7
MscG Avatar answered Oct 09 '22 19:10

MscG