0

I am doing Java Native Development for android. And I use Android NDK and eclipse as IDE. Very frequently I write a C/C++ code in jni and eclipse shows errors such as:

Could not be resolved:

  1. JNIEXPORT
  2. JNICALL
  3. JNIEnv
  4. jobject
  5. jint

But on the other hand ndk-build builds the .so file sucessfully without any error or even warnings. How to fix this in eclipse?

If you need here is the code I compile:

#include <jni.h>
#include <unistd.h>

int multiply(int i, int j) {
         int x = i * j;
         return x;
}

extern "C" {
         JNIEXPORT jint JNICALL Java_cookbook_chapter3_HelloNDKGDBActivity_multiply(JNIEnv* env, jobject o, jint pi, jint pj){
           int i = 1, j = 0;
           while (i) {
             j=(++j)/100;
           }
           return multiply(pi, pj);
        }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Narek
  • 38,779
  • 79
  • 233
  • 389

2 Answers2

2

Try to refresh project tree. Very frequently eclipse shows error, why when you click on the project and press F5 (refresh), errors are gone. But is they don't then please try the approach below:

turn off all checks in the Project Properties -> C/C++ General -> Code Analysis

See actual answer here: Syntax error notification in native code in Eclipse using the newest NDK r8d

Community
  • 1
  • 1
Narek
  • 38,779
  • 79
  • 233
  • 389
0

I've already had these kind of issues. I don't know if it's your case, but, it might be. Anyway, my CDT eclipse plugin does not work very well and every time I edit or even open a C/C++ file, it gets full of errors. But, I can change my files normally and the ndk-build works properly. Have you tried another C/C++ file editor? It can be a solution to stop getting these errors.

Hime
  • 369
  • 3
  • 15
  • Have used TextWrangler editor and magic - that helped. :) Also I have copied the dode from a .pdf file using `Preview`. Maybe this was a reason too, I don't know. But thanks :) – Narek Jun 01 '14 at 21:58
  • But I guess this is not the only way it occurs. It can occur without any reason too. I have even removed CDT, NDK and re-downloaded them to fix it. I think Eclipse is not a stable IDE. – Narek Jun 02 '14 at 02:57
  • It's better to set these configurations that you've listed bellow on Eclipse Properties (Window > Preferences > C/C++ > Code Analysis). This way, you won't have to apply them every time you use some native code file. – Hime Jun 03 '14 at 12:32