JNIEXPORT and JNICALL on Android NDK

When working with some sources written in C ++, I found these macros:

JNIEXPORT return_type JNICALL function_name (...) {However, Android NDK samples do not use them. I read some docs from Oracle, but I'm still confused.

Do I have to use them while working with Android NDK?

One of the reasons for the request is highlighting the macro break syntax in eclipse CDT :)

+7
source share
2 answers

This is basically a windows problem, if you look at the jni_md_win32.h file that comes with Oracle jdk, this is the macro definition:

/* * @(#)jni_md.h 1.14 03/12/19 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ #ifndef _JAVASOFT_JNI_MD_H_ #define _JAVASOFT_JNI_MD_H_ #define JNIEXPORT __declspec(dllexport) #define JNIIMPORT __declspec(dllimport) #define JNICALL __stdcall typedef long jint; typedef __int64 jlong; typedef signed char jbyte; #endif /* !_JAVASOFT_JNI_MD_H_ */ 

In the jni_md_linux.h header, these macros are empty. Therefore, I assume that as long as you do not want your native code to be executed in windows using the oracle JVM, you can delete these macros.

+10
source

Make sure that the added path to the platform you want from the Android NDK has been added to your C \ C ++ project. This can be done as follows:

  • Open project properties
  • Expand C / C ++ General Information
  • Click "Paths and Symbols"
  • In the "Include" section, add the path to the include folder of the desired NDK platform (for example, $ {ANDROID_NDK_HOME} \ platform \ android-9 \ arch-arm \ usr \ include)
+1
source

All Articles