srijith
srijith

Reputation: 71

unresolved inclusion in the java header in JNI

This is my java file for which i wanted to generate a header file using javah for an android opencv application.

package com.hosa;

public class edgejava{
static{
    System.loadLibrary("edgejava");
}
public native int main(``);
}

The generated header file is as below.

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_hosa_edgejava */

#ifndef _Included_com_hosa_edgejava
#define _Included_com_hosa_edgejava
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class:     com_hosa_edgejava
* Method:    main
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_hosa_edgejava_main
(JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

the eclipse is pointing out that inclusion of jni.h in the header file is unresolved. what are the steps to be taken to solve this????

regards, srijith

Upvotes: 7

Views: 20794

Answers (4)

Volodymyr Kulyk
Volodymyr Kulyk

Reputation: 6546

FIXED!

Add to Application.mk:
APP_STL := gnustl_shared

Go to Properties -> C/C++ General -> Preprocessor Include-> Entries -> Add -> Include Directory -> File System Path, and select the path of the includes like:

${NDK_ROOT}\platforms\android-21\arch-arm\usr\include
${NDK_ROOT}\sources\cxx-stl\gnu-libstdc++\4.8\libs\armeabi-v7a\include
${NDK_ROOT}\sources\cxx-stl\gnu-libstdc++\4.8\include
${NDK_ROOT}\toolchains\arm-linux-androideabi-4.8\prebuilt\darwin-x86_64\lib\gcc\arm-linux-androideabi\4.8\include

!!! Check "Contains system headers" checkbox for each included path. !!!

Go to Properties -> C/C++ General -> Preprocessor Include-> Providers -> Check CDT GCC Built-in Compiler Settings -> OK

Clean and rebuild your project.

Upvotes: 1

hao
hao

Reputation: 29

In my case, I just closed and open the project, then the errors disappeared.

Upvotes: -3

Sriram Murali
Sriram Murali

Reputation: 6234

I had the same problem with Android JNI. I fixed it by pointing the project to the include path of android jni.h in the NDK source See how to download NDK from here: https://developer.android.com/tools/sdk/ndk/index.html

Details about the fix is here:

Android Add Native support - unresolved jni.h, android/log.h etc

Upvotes: 0

Idistic
Idistic

Reputation: 6311

I am having issues with this as well so for anyone that stumbles on this ...

I solved the JNI issue from eclipse - you may have already done step 1 or something similar

  1. File -> New -> Other-> C++ > Convert to C++ Project

  2. RIght Click on Project Head -> Properties -> C++ General -> Paths And Symbols

  3. Add a path similar to this under GNU and GNUC++ Language Entries

    /NDK/Platforms/Android-9/arch-arm/usr/include

    Your path will be different dependent on how you are setup, which platform number etc.

    Once done then rebuild the indexes when it prompts you

  4. Close your project, re-open it, then clean-build (or it might happen immediately)

In my case the JNI.h was then found BUT the JNIEnv etc. were still unrecognized even though they are in the JNI.h file.

Also note for anyone having this issue it wont stop you from building, you just need to close the offending files, then open and close your project to get rid of the errors (what a pain)

UPDATE: FIXED!

In edition to the Above in Indigo do the following from the menu / dialog

Window->Preferences->C/C++->Index check the "Index Unused Headers" reindex/build if necessary

You might also need to add "/NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/include" above the include I mentioned above to the language entries.

All symbols are now recognized - Hope this helps someone it was driving me nuts.

Upvotes: 26

Related Questions