9

Before today i use Eclipse 3.8 with Sequoyah plugin for Android NDK project. But today i decide to freshen Eclipse to Juno release with SDK and NDK.
I was very happy then i see Android Native Tools in ADT installation, which will do the same job like Sequoyah, but with debug feature.
I created new Android Project to test it.
Adding Android Native Support create jni folder with Android.mk, .cpp file, well same that Sequayah do. Then i get first unresolved to jni.h. I get similar bug with Sequoyah, so i rebuild index and restart Eclipse. After restart it not disappeared.
I go to Paths And Symbols at C/C++ properties. But there are all that needed built-in includes.
(NDK PATH)/platforms/android-8/arch-arm/usr/include - there are jni.h, log.h etc.
I tryed to add extra dublicate includes to jni.h, clean project, restart, rebuild index, change .ccp to .c, it stays unresolved. I got no errors in error log, but syntax errors in editor on jni functions.

NativeLib.java

package com.aristarhys.glow;

public class NativeLib 
{
private static final String NATIVE_LIB = "glow";
static 
{
    System.loadLibrary(NATIVE_LIB); 
}
  private NativeLib(){};
  public static native void test();
}

glow.h

#ifndef GLOW_H_
#define GLOW_H_

#include <jni.h> //unresolved
//syntax error
JNIEXPORT void JNICALL Java_com_aristarhys_glow_NativeLib_test(JNIEnv* env, jclass cls);
#endif /* GLOW_H_ */

log.h

#ifndef LOG_H_
#define LOG_H_

#include <android/log.h> //unresolved

#define INFO_TAG "[INFO]"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, INFO_TAG, __VA_ARGS__)

#endif /* LOG_H_ */

glow.c

#include "glow.h"
#include "log.h"

//syntax error
JNIEXPORT void JNICALL Java_com_aristarhys_glow_NativeLib_test(JNIEnv* env, jclass cls)
{
LOGI("HI");
}

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := glow
LOCAL_SRC_FILES := glow.c
LOCAL_LDLIBS    := -llog
include $(BUILD_SHARED_LIBRARY)
Aristarhys
  • 2,092
  • 7
  • 37
  • 68

4 Answers4

29

I've tried android-ndk-r8b with C:\Android\android-ndk-r8b in my PATH variable. Project compiled without error.
However eclipse "says" that Unresolved inclusion: <jni.h>

solved:

NDK Project->New->Folder->Advanced->Link to alternate location(Linked Folder) Browse the path(for example):C:\Android\android-ndk-r8b\platforms\android-8\arch-arm\usr\include

ra.
  • 1,798
  • 14
  • 15
  • I want to create a JNI project. I want to use **CURL(curl/curl.h)** include which is available in Cygwin. Therefore I created combined Android and C/C++ project as this library was available as Cygwin headers. But I am still getting **fatal error: curl/curl.h: No such file or directory** error. What could be the problem? Can we refer to external Cygwin libraries in Android JNI project? – AndroidDev Nov 22 '12 at 06:19
  • look here : http://code.google.com/p/ra-sqlite/source/browse/ra.sqlite/jni/android/raSqlite.mk Hope it helps you to figure out an issue ( `cf_includes := $(addprefix -Ijni/android/,$(cf_includes_local))` ) – ra. Nov 23 '12 at 16:03
3

You can do this by choosing Properties for the project

Properties -> C/C++ General -> Preprocessor Include..-> Entries -> Setting Entries -> CDT User Setting Entries

Add -> Include Directory -> File System Path, and enter the path of the includes

ndk/platforms/android-[version]/[arch]/usr/include
Sriram Murali
  • 5,804
  • 2
  • 26
  • 32
  • Good practice there to use enviropment variable NDK_ROOT so path can be like this: ${NDK_ROOT}\platforms\android-5\arch-arm\usr\include Also I found that this working for me only if I checked "Contains system headers" checkbox. – Fedir Tsapana Sep 02 '14 at 08:49
3

I often solving similar issues that is probably occur when you move or rename the working folder of the project.

  1. No any environment variables required, just pointed NDK location under Preferences > Android > NDK.
  2. Move project outside workspace. Delete from project next files/folders:

.settings
.classpath
.cproject
.project
project.properties

  1. Reimport your project. Eclipse > New > Other > Android > Android Project from Existing Code > then point folder with your project, let Eclipse detect it, check "Copy project into workspace" and click Ok/Next, whatever.
  2. Clean project.
  3. Right click on project > Android Tools > Add native support
  4. Rebuild, possibly restart workspace.

Also this solved issue with Eclipse 4.3 previously ignored build system and user defined compiler flags. Now macros folding dependent on this flags works fine.

If more general: NDK plugin can properly define for you right includes and anything other required to work fine, but you need to clean your project from broken crap, and easiest way to do so is reimport project.

Dmitry Ratty
  • 425
  • 1
  • 10
  • 13
2

If you are using Eclipse Kepler the path to add the NDK include

Properties->C/C++ General->Paths and Symbols.

on my version of NDK the include path needed was:

C:\Program Files (x86)\Android\android-sdk\NDK\android-ndk-r10\platforms\android-L\arch-arm\usr\include.

It will ask you if you want to rebuild. Afterwards the errors go away.

vbmrupp
  • 33
  • 5