1

If I have my Android NDK project use a .c file instead of .cpp I cannot resolve any functions inside JNIEnv*. Here is how I'm trying to use it:

(*env)->GetCharArrayElements(chrs, 0);

I have also tried:

GetCharArrayElements(env, chrs, 0);
env->GetCharArrayElements(chrs, 0);

This is getting frustrating as I have some c library projects that I would like to include but if I have .cpp file then the library will need to be ported somehow and I would like to avoid that. Any help/ideas would be great.

Here is my Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := NDKDemo
LOCAL_SRC_FILES := NDKDemo.c

include $(BUILD_SHARED_LIBRARY)

edit:

Here is how I'm declaring JNIEnv*

#include <jni.h>
JNIEXPORT void JNICALL Java_com_atd_ndkdemo_NDKDemo_charManip(JNIEnv* env, jobject obj, jcharArray chrs) 

    jchar* cchar0 = GetCharArrayElements(chrs, 0);
    jchar* cchar1 = (*env)->GetCharArrayElements(env, chrs, 0);
    jchar* cchar2 = (*env)->GetCharArrayElements(chrs, 0);
    jchar* cchar3 = env->GetCharArrayElements(chrs, 0);
}

Interestingly, cchar0 doesn't complain until I try to compile, then eclipse tells me it cannot be resolved again.

bustedware
  • 194
  • 1
  • 3
  • 18
  • Try `(*env)->GetCharArrayElements(env, chrs, 0)`. What is the error you're getting? – fadden Dec 22 '14 at 01:20
  • Method GetCharArrayElements cannot be resolved – bustedware Dec 22 '14 at 01:22
  • Maybe `env` has the wrong type? How is the method declared? – fadden Dec 22 '14 at 01:27
  • added an update to original post – bustedware Dec 22 '14 at 01:36
  • I'm also getting undefined reference to 'GetCharArrayElements', so cchar0 seems to be right, just for some reason it is undefined/ not being linked? – bustedware Dec 22 '14 at 01:40
  • Take a look at a copy of jni.h (say, https://android.googlesource.com/platform/dalvik/+/gingerbread/libnativehelper/include/nativehelper/jni.h). Note that GetCharArrayElements is a member of a struct. The fact that you are able to find it globally makes me wonder if there's a `#define` somewhere that is messing things up. There should be no GetCharArrayElements function visible to the NDK linker -- it's only accessible as a member of the struct. – fadden Dec 22 '14 at 01:48
  • Okay this is really weird. I just reinstalled NDK plugin for eclipse and NDK and am using cchar1. The errors still come up saying Method 'GetCharArrayElements' could not be resolved but it compiles. I still can't run the whole project becuase it thinks there are errors – bustedware Dec 22 '14 at 02:05
  • Note re-asked -- and answered -- in http://stackoverflow.com/questions/27608634/weird-jni-ndk-behavior-in-eclipse-3-8 – fadden Dec 23 '14 at 01:44

0 Answers0