Android NDK - Unable to use jstring, keeps crashing

I've spent the last two days on a JNI issue and it was driving me crazy ... I'm just trying to do:

  SWIGEXPORT void JNICALL Java_com_my_package_CM_1CoreJNI_CM_1Property_1name_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
    const char *arg2 = (*jenv)->GetStringUTFChars(jenv, jarg2, 0);


I call this function via JAR and it keeps crashing. All I can read from my LogCat:

03-27 12:44:29.162: E/dalvikvm(1599): JNI ERROR (app bug): accessed stale weak global reference 0x4080f657 (index 15765 in a table of size 0)
03-27 12:44:29.172: W/dalvikvm(1599): JNI WARNING: jstring is an invalid weak global reference (0x4080f657)
03-27 12:44:29.172: W/dalvikvm(1599):              in Lcom/my/package/CM_CoreJNI;.CM_Property_name_set:(JLjava/lang/String;)V (GetStringUTFChars)


After a lot of research, I tried to call this function directly from my activity (adding my own set of voids ...) and it worked fine! I'm blocked and don't know how to do it ...

Did anyone manage to call JNI from the JAR?

EDIT: Fixed by removing the jar and adding .java files ...


source to share

All Articles