Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android C++ NDK

I am trying to compile the following for the android ndk

#include <jni.h>
#include <string.h>

extern "C" {
    JNIEXPORT jstring JNICALL Java_com_knucklegames_helloCpp_testFunction(JNIEnv * env, jobject obj);
};

JNIEXPORT jstring JNICALL Java_com_knucklegames_helloCpp_testFunction(JNIEnv *env, jobject obj) {
 return env->NewStringUTF(env, "Hello from native code!");
}

but it is giving the following error

Compile++ thumb: helloCpp <= /cygdrive/c/workspace/helloCpp/jni/main.cpp
/cygdrive/c/workspace/helloCpp/jni/main.cpp: In function '_jstring* Java_com_knucklegames_hello
Cpp_testFunction(JNIEnv*, _jobject*)':
/cygdrive/c/workspace/helloCpp/jni/main.cpp:10: error: no matching function for call to '_JNIEn
v::NewStringUTF(JNIEnv*&, const char [24])'
/cygdrive/d/android/android-ndk-r4b/build/platforms/android-8/arch-arm/usr/include/jni.h:839: note: candidates
 are: _jstring* _JNIEnv::NewStringUTF(const char*)
make: *** [/cygdrive/c/workspace/helloCpp/obj/local/armeabi/objs/helloCpp/main.o] Error 1
like image 491
Will03uk Avatar asked Oct 25 '10 11:10

Will03uk


1 Answers

The NewStringUTF function only takes one argument, a c-string:

env->NewStringUTF("Hello from native code!");

There is a C version that goes like this:

NewStringUTF(env, "Hello from native code!");

But you are obviously using the C++ version.

like image 92
Benjamin Lindley Avatar answered Sep 23 '22 04:09

Benjamin Lindley