java-native-interface

Android - accessing files in native C/C++ code with Google Scoped Storage API

拟墨画扇 提交于 2021-02-18 22:26:33
问题 I need to open files by file name in Android apps within native C/C++ code. The native code are 3rd party libraries that I would prefer not to modify, but they often require file name as an argument to read/write files. With the Google's "scoped storage" API and disabling native access to files in Android 10 or later, it's a real problem. One well known solution is to get a file descriptor and use "proc/self/fd/FD_NUMER" trick, like: ParcelFileDescriptor mParcelFileDescriptor = null; String

JNI thread model?

我只是一个虾纸丫 提交于 2021-02-17 21:47:10
问题 When I call a C/C++ from Java, is a new thread created by JavaVM or JNI to run the C/C++ code while my Java thread is waiting? I ask this because my C/C++ code runs something on the GPU and I need to check a specific buffer to get the result back. Once I have the result, I need to call my Java function again. So I was thinking of creating a thread on the C++ side that continuously checks the buffer and once there is some data available, makes a call back to the Java side. 回答1: The JNI does

How to convert the contents of a Java byte array to C string in JNI?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-16 08:53:54
问题 Update: Error: jbyte* elements = (*env)->GetByteArrayElements(env, array, NULL); returns only 8 bytes. Provide any alternative to way to retrieve byte form jbytearray. I'm new in JNI so I'm not familiar in JNI and also English. Now I try the simple JNI program on File reading in Java and write it into file using C. File reading java code: public class FileIO { static { System.loadLibrary("io"); } private native void writeToFile(byte[] msg); public static void main(String[] args) throws

How to convert the contents of a Java byte array to C string in JNI?

浪尽此生 提交于 2021-02-16 08:53:15
问题 Update: Error: jbyte* elements = (*env)->GetByteArrayElements(env, array, NULL); returns only 8 bytes. Provide any alternative to way to retrieve byte form jbytearray. I'm new in JNI so I'm not familiar in JNI and also English. Now I try the simple JNI program on File reading in Java and write it into file using C. File reading java code: public class FileIO { static { System.loadLibrary("io"); } private native void writeToFile(byte[] msg); public static void main(String[] args) throws

How to get the Android context instance when calling JNI method?

五迷三道 提交于 2021-02-16 08:41:39
问题 I have already read some relevant answers on stackoverflow,but seems no one has answered my question.I will get the android ID from native code,i.e. calling the method getAndroidIDfromNativeCode in C code,(so the JVM is inited in the native code by method create_vm),you know that when calling the method getContentResolver ,you must use a Android Context instance to call it,so how to get this Context instance ? static jstring native_code_getAndroidID(JNIEnv *env, jobject thiz) { jclass c

How to get the Android context instance when calling JNI method?

☆樱花仙子☆ 提交于 2021-02-16 08:41:25
问题 I have already read some relevant answers on stackoverflow,but seems no one has answered my question.I will get the android ID from native code,i.e. calling the method getAndroidIDfromNativeCode in C code,(so the JVM is inited in the native code by method create_vm),you know that when calling the method getContentResolver ,you must use a Android Context instance to call it,so how to get this Context instance ? static jstring native_code_getAndroidID(JNIEnv *env, jobject thiz) { jclass c

JNI WArning :Method called with exception pending

廉价感情. 提交于 2021-02-11 17:57:31
问题 I have built the app i release mode using proguard.and I am getting this error. 01-20 15:16:37.611: W/dalvikvm(31760): JNI WARNING: JNI method called with exception pending 01-20 15:16:37.611: W/dalvikvm(31760): Pending exception is: 01-20 15:16:37.616: W/System.err(31760): java.lang.RuntimeException: Stub When i build apk in normal way it works on my device but following release mode it does not work. 回答1: The documentation states You must not call most JNI functions while an exception is

JNI WArning :Method called with exception pending

☆樱花仙子☆ 提交于 2021-02-11 17:57:14
问题 I have built the app i release mode using proguard.and I am getting this error. 01-20 15:16:37.611: W/dalvikvm(31760): JNI WARNING: JNI method called with exception pending 01-20 15:16:37.611: W/dalvikvm(31760): Pending exception is: 01-20 15:16:37.616: W/System.err(31760): java.lang.RuntimeException: Stub When i build apk in normal way it works on my device but following release mode it does not work. 回答1: The documentation states You must not call most JNI functions while an exception is

jemalloc generating many files

痴心易碎 提交于 2021-02-11 13:50:21
问题 I followed the jemalloc instructions and setup the jemalloc on centOS 7. However, soon after setting export LD_PRELOAD=/usr/local/lib/libjemalloc.so export MALLOC_CONF=prof_leak:true,lg_prof_sample:50,lg_prof_interval:62,prof_final:true environment variables, I could see a lot of jeprof.*.heap files being written to my current directory. I didn't start my jetty server at all, still, so many files are generated. Which process is generating it? When I tried to start the application as follows

%1 is not a valid Win32 application

末鹿安然 提交于 2021-02-11 08:23:04
问题 I want to make a .dll in Qt, and to use generated .dll in a Java project in Eclipse. I've followed this tutorial to create a working dll. The full code that works is given below: jniProjectExample_JniExample.h /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class jniProjectExample_JniExample */ #ifndef _Included_jniProjectExample_JniExample #define _Included_jniProjectExample_JniExample #ifdef __cplusplus extern "C" { #endif /* * Class: jniProjectExample