Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
like image 420
Aristarhys Avatar asked Sep 25 '12 13:09

Aristarhys


2 Answers

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

like image 125
ra. Avatar answered Oct 18 '22 19:10

ra.


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
like image 22
Sriram Murali Avatar answered Oct 18 '22 21:10

Sriram Murali