Unauthorized inclusion in java header in JNI

This is my java file for which I wanted to create a header file using javah for android opencv application.

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

The generated header file is as follows.

 /* 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 

an eclipse indicates that jni.h is not allowed in the header file. What steps should be taken to solve this problem?

Regards, srijith

+7
source share
4 answers

I am having problems with this, as well as for those who stumble upon this ...

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

  • File β†’ New β†’ Other-> C ++> Convert to C ++ Project

  • RIght Click on the project head β†’ Properties β†’ C ++ General β†’ Paths and Symbols

  • Add a path similar to this according to the GNU and GNUC ++ language entries

    / NDK / Platforms / Android 9 / Lever Arch / USR / Include

    Your path will differ depending on how you configure, which platform number, etc.

    After that rebuild the indices when it prompts you

  • Close the project, open it, then clean it (or it can happen immediately)

In my case, JNI.h was found, but JNIEnv, etc. still not recognized, even if they are in the JNI.h file.

Also note that for those who have this problem, it will not stop you from creating, you just need to close the violating files, and then open and close the project to get rid of errors (what a pain)

UPDATE: FIXED!

In the edition above in Indigo, follow these steps from the menu / dialog

Window-> Settings-> C / C ++ β†’ Index checks the "Index of unused headers" reindex / build if necessary

You may 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 included I mentioned above about language records.

All characters are now recognized. Hope this helps someone that drives me crazy.

+26
source

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 to include, for example:

 ${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 the "Contains system headers" box for each incoming path. !!!

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

Clean and rebuild your project.

+1
source

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

Details about the fix are here:

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

0
source

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

-3
source

All Articles