Skip to content

Instantly share code, notes, and snippets.

@suvasish114
Created May 8, 2021 08:59
Show Gist options
  • Save suvasish114/67db5bbdc794bbe6e3aed47ba9bda471 to your computer and use it in GitHub Desktop.
Save suvasish114/67db5bbdc794bbe6e3aed47ba9bda471 to your computer and use it in GitHub Desktop.
#include<jni.h>
#include<stdio.h>
#include "NativeDemo.h"
JNIEXPORT void JNICALL Java_NativeDemo_test(JNIEnv *env, jobject obj){
jclass cls;
jfieldID fid;
jint i;
printf("Inside native method.");
cls = (*env) ->GetObjectClass(env, obj);
fid = (*env) ->GetFieldID(env, cls, "i", "I");
if(fid == 0){
printf("Could not get field ID.");
return;
}
i=(*env)->GetIntField(env, obj, fid);
printf("i = %d\n", i);
(*env)->SetIntField(env, obj, fid, 2*i);
printf("Ending of native method.");
// function body
printf("Hello world");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment