jni: avoid crashing when run on ART

The ART runtime is stricter about calling env->DeleteWeakGlobalRef
on an object/value that was not returned from env->NewWeakGlobalRef.
In that case, it triggers an abort which causes the application to
crash and display an "Application has stopped" dialog message.