2

trying to create a new native project for android but running into weird issue. I created a new project and selected 'Android Tools > Add Native Support', then after it's created when I press Run eclipse complains about some problems including jni.h. I checked that the C/C++ Paths and Symbols were set correctly by the ADT and it appears fine:

C/C++ Paths and Symbols

However I get compiler errors in my cpp code from Eclipse. But what's weird is when I run ndk-build on the project through the terminal it works fine, see below:

Running ndk-build from Terminal

Running project from Eclipse

Also here's the code (jnitest.cpp):

#include <jni.h>

JNIEXPORT jstring JNICALL Java_com_brianrojas_jnitest_MainActivity_echo
    (JNIEnv *env, jobject object, jstring input)
{
    return input;
}

So it looks like the libraries can build OK but Eclipse just doesn't like it for some reason and won't install the app on my phone. Any ideas what I'm doin wrong? Also below is my android eclipse plugin info incase that helps.

Android plugins for Eclipse

marchinram
  • 5,698
  • 5
  • 47
  • 59
  • did you refresh your project after creating .so file ? – Lucifer Jul 21 '12 at 02:26
  • just tried that, cleaned the project, built it and refreshed and same error – marchinram Jul 21 '12 at 21:11
  • i figured out a way to ghetto rig it to get it to work, i just press run in eclipse, it says there was an error and doesn't install the apk on the device, but it does build it, so i just run adb install -r after the error popup and it runs fine – marchinram Jul 22 '12 at 03:51
  • another thing i noticed aswell is that I can close the project and then open it, and eclipse won't complain at all. I can then press run and it will run the project fine. But the second I open a .cpp file it starts complaining about those errors again – marchinram Jul 22 '12 at 04:15

2 Answers2

5

I know what might be wrong: Eclipse Juno.

Just download Eclipse Indigo and it should work. This is a known bug. Apparently it can also happen if you're developing on windows:

Known Issues

  1. Eclipse does not automatically find the include paths to all the NDK headers on Windows. This issue will be fixed in the next update (20.0.1) when it is released.
  2. Eclipse does not automatically find the include paths with CDT 8.1.0 (Juno). This issue is tracked in Bug 33788.

http://tools.android.com/recent/usingthendkplugin

Nikhil
  • 16,194
  • 20
  • 64
  • 81
0

I had exactly the same problem.

(removed confused suggestions)

Edit: I have just added new include directories, and now I am more confident about the way to make it work: after modifying the include directories in project properties/C/C++ general/Paths and Symbols, Eclipse shows a dialog box to offer to index the new include files. It is important to accept and re-index the include files.

Rémi
  • 3,705
  • 1
  • 28
  • 39