17
votes

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.

3
#include <jni.h> The only header required for using jint and JNIEnv is jni.h. However, you have to use them within extern "C". May be posting some part of your code can help - codetiger
If the code builds with ndk-build your problem is just with eclipse. Somewhere in a menu it needs to be pointed at the ndk includes, or simply disable the ndk plugin so it doesn't care. - Chris Stratton
I can't figure out how to paste a code block without it coming out like plain text. Suffice to say it is a very very simple autogenerated header file for a function that multiplies two numbers together. @chris Where should I disable the ndk plugin? - Gatica

3 Answers

19
votes

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.

17
votes

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.

7
votes

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.