Search code examples
javaandroidc++android-ndkjava-native-interface

Eclipse shows error, while ndk_build is successful


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);
        }
}

Solution

  • 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