17

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.

Gatica
  • 593
  • 1
  • 6
  • 13
  • 2
    #include 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 Jul 26 '12 at 10:10
  • 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 Jul 26 '12 at 12:35
  • 1
    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 Jul 30 '12 at 14:53

3 Answers3

19

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.

weston
  • 54,145
  • 21
  • 145
  • 203
17

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.

Yury
  • 20,618
  • 7
  • 58
  • 86
  • 1
    You can see the .project file in the Navigator view and edit it Eclipse's project file editor. – Tom Blodget May 02 '13 at 14:17
  • Had the same issue and this answer solved it. First I thought OpenCV caused the issues somehow, but eclipes was the reason. Thank you, such a time saver! – vRallev Sep 03 '13 at 13:13
  • Thanks! Awhile back, but forgot to update. I'd reimported the project as well as applied that fix and then it worked. – Gatica May 21 '14 at 14:37
7

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.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
MscG
  • 366
  • 2
  • 15
  • I think there are an assortment of issues with Auto indexing in Eclipse (Kepler), ADT, and CDT. I tried many but this fixed my problem as most of our code is C rather than CPP. – Cookster Aug 25 '14 at 22:20