Should Java finalizer really be avoided also for native peer objects lifecycle management?

finalize and other approaches that use GC knowledge of objects lifetime have a couple of nuances: visibility: do you guarantee that all the writes methods of object o made are visible to the finalizer (i.e., there is a happens-before relationship between the last action on object o and the code performing finalization)? reachability: how do … Read more

Why do some Android phones cause our app to throw an java.lang.UnsatisfiedLinkError?

EDIT: Since I got another crash report yesterday for one of my apps I dug a bit deeper into the matter and found a third very likely explanation for that problem: Google Play Partial APK Update Goes Wrong To be honest, I did not know about that feature. The APK file name suffix “-2.apk” made … Read more

NDK – How to use a generated .so library in another project

There is a much simpler way to do all of this. Let’s say that your prebuilt library is called “libprebuilt.so” In the project folder of the new project you want to only include the prebuilt library, do something like: mkdir -p jni/libprebuilt cp libprebuilt.so jni/libprebuilt Then, just create a jni/libprebuilt/Android.mk file: LOCAL_PATH := $(call my-dir) … Read more

Calling Rust from Java

Apart from the problem that *mut Any/*const Any are fat pointers, there is also a fact that native JNI functions use double indirection when accessing JNINativeInterface structure: struct JNINativeInterface_; typedef const struct JNINativeInterface_ *JNIEnv; jint (JNICALL *GetVersion)(JNIEnv *env); Here, you can see that JNIEnv is a pointer to JNINativeInterface_ structure which actually contains the fields … Read more

Can I call Java from Node.js via JNI and how?

You should try the node-java npm module which is a well-written wrapper over JNI. node-jave doesn’t appear to (yet) have broad adoption, but playing with it, I’ve been impressed with how straightforward and robust it has been. It’s as simple as: var list = java.newInstanceSync(“java.util.ArrayList”); list.addSync(“item1”); list.addSync(“item2”); console.log(list.getSync(1)); // prints “item2” You can do just … Read more

NewStringUTF() and freeing memory

The storage for the const char* argument to NewStringUTF() is entirely your responsibility: if you allocated test with malloc(), then you need to free() it. So, the snippet you posted is correct. You are corrupting the heap somewhere else. I see conflicting opinions. Some say I should free it myself, some say the VM frees … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)