Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse ADT - Unresolved inclusion jni.h

On my Windows platform, I have the latest version of adt bundle (20140321) and ndk (r9d) installed. The installation is as clean as it gets. The environment variables NDK_ROOT, PATH, etc. are all defined properly.

The app I am working on has some C++ native code. The code builds fine both outside Eclipse as well as within Eclipse.

The problem, however, is that the editor complains that jni.h is an unresolved inclusion.

Project-->Properties-->C/C++ General-->PathsAndSymbols shows include directories and one of the directories is C:\adt\ndk\platforms\android-19\arch-arm\usr\include. I have verified that jni.h is present in this directory.

I have already checked all other messages on this forum but couldn't find any concrete steps. Appreciate your guidance. Regards.

like image 473
Peter Avatar asked Apr 17 '14 01:04

Peter


3 Answers

I ran into a similar problem with a working project with Android NDK-based code after updating to Eclipse Kepler. I observed similar things: the header files would correctly be listed under "includes" in the project, the actual build (via ndk-build) worked fine, but Eclipse's editor couldn't locate any headers in standard system directories (all headers with < > brackets).

I tried many different fixes, including switching toolsets, rebuilding indices etc. without success.

Finally, I removed the C nature entirely from the project, and added it back via the "Android Tools" menu in Eclipse.

Removing the C nature:

The only way I could find to reliably removed the C nature from the project was by hand editing Eclipse's .project file for the project.

  1. Close the Eclipse project (e.g. by quitting Eclipse).

  2. Open the .project file in a text or xml editor. There will be at least 2 <buildCommand> nodes that need to be removed. Remove the <buildCommand> node with name org.eclipse.cdt.managedbuilder.core.genmakebuilder and all its children, and the <buildCommand> node with name org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder and its children. Finally, remove the lines:

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

  3. Completely remove the .cproject file.

Adding back the Android Native nature

Reopen the project in Eclipse. Then right-click on the project in the Project Explorer, and from the "Android Tools" contextual menu, choose "Add Native Support...".

Android Tools -> Add Native Support...

Looking at the changes made in the .project and .cproject files before and after this change, it appears that it primarily gave new version numbers to the Android NDK tools. In any case, it solved the issue for me.

like image 160
bleater Avatar answered Sep 20 '22 14:09

bleater


after add native support,right click project, add includes in c/c++ general--> paths and symbols >> includes, for example add include as %NDK_HOME%\platforms\android-19\arch-arm\usr\include

like image 3
Jianxing Fan Avatar answered Sep 19 '22 14:09

Jianxing Fan


I had the same problem some days ago. I found a fix in another question here in stackoverflow, but now I can't find the link.

In Eclipse: right-click on your project > Properties > C/C++ General > Code Analysis > Launching and disable both options ("Run with build" and "Run as you type").

There seems to be a problem with CDT and the Indexer, doing this you hide the problem. The editor will still complain but now you should be able to run and debug your application.

like image 1
Pau Guillamon Avatar answered Sep 23 '22 14:09

Pau Guillamon