java-native-interface

Why does JNI Global reference have Maximum number limit?

拈花ヽ惹草 提交于 2020-07-09 11:54:09
问题 As we known, JNI is a bridge between Java and C++. Recently i'm coding for a Java project and it's main module is based on C++ which need to store a large number of GlobalReference . And it will increase along with activity being opened. Therefore the maximum number (65535) of GlobalReferences become a serious problem and i have to solve the problem using peculiar method. So i'm interested in why there is a limit on GlobalReferences . Is it only for detecting the memory leaks as other's

“undefined symbol: __cxa_pure_virtual” error when loading library from java

江枫思渺然 提交于 2020-07-07 07:33:31
问题 I have a Java program that needs to load a native code library (through JNI with SWIG) but when I tried to run it I got an error as follows: Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/local/lib/libmyapp_jni.so.0.0.0: /usr/local/lib/libmyapp_jni.so.0.0.0: undefined symbol: __cxa_pure_virtual at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864) at

How to load a JNI .dylib file with a dependency without getting an UnsatifiedLinkError?

自闭症网瘾萝莉.ら 提交于 2020-06-26 12:07:52
问题 Goal: Link Java to Swift Problem: I get an UnsatisfiedLinkError when trying to load a JNI .dylib file that is linked with a Swift .dylib file when calling System#loadLibrary(String). Expected Behavior: The dependency of the Java .dylib would be automatically loaded or the call to System.loadLibrary("SwiftCode") would load the dependency (the only solution I could come up with). Note: I am combining this github tutorial and this Medium article to create my JNI .dylib file and this tutorial to

Android JNI C simple append function

感情迁移 提交于 2020-06-25 05:30:26
问题 Id like to make a simple function, that return value of two Strings. basically: java public native String getAppendedString(String name); c jstring Java_com_example_hellojni_HelloJni_getAppendedString(JNIEnv* env, jobject thiz, jstring s) { jstring sx = (*env)->GetStringUTFChars(env, s, NULL); return ((*env)->NewStringUTF(env, "asd ")+sx); } its say jni/hello-jni.c:32: warning: initialization discards qualifiers from pointer target type jni/hello-jni.c:34: error: invalid operands to binary +

Android JNI C simple append function

[亡魂溺海] 提交于 2020-06-25 05:30:01
问题 Id like to make a simple function, that return value of two Strings. basically: java public native String getAppendedString(String name); c jstring Java_com_example_hellojni_HelloJni_getAppendedString(JNIEnv* env, jobject thiz, jstring s) { jstring sx = (*env)->GetStringUTFChars(env, s, NULL); return ((*env)->NewStringUTF(env, "asd ")+sx); } its say jni/hello-jni.c:32: warning: initialization discards qualifiers from pointer target type jni/hello-jni.c:34: error: invalid operands to binary +

Write error: Invalid argument, when file is opened with O_DIRECT

南笙酒味 提交于 2020-06-18 08:34:07
问题 it is very important to me to write to a file with the O_DIRECT flag. This is how I open the file: //Open the file int fd; if((fd = open(inFilepath, O_WRONLY | O_CREAT |O_SYNC |O_DIRECT,S_IRUSR|S_IWUSR))<0) { //Error handling return; } I know about O_DIRECT's alignment restrictions. This is why I initialize my buffer with calloc: char *buff = (char *) calloc((size_t) 1,sizeof(char)); if(write(fd,buff,(size_t)1)<1) { //Error logging free(buff); return -1; } And I get the write: Invalid

Write error: Invalid argument, when file is opened with O_DIRECT

房东的猫 提交于 2020-06-18 08:32:29
问题 it is very important to me to write to a file with the O_DIRECT flag. This is how I open the file: //Open the file int fd; if((fd = open(inFilepath, O_WRONLY | O_CREAT |O_SYNC |O_DIRECT,S_IRUSR|S_IWUSR))<0) { //Error handling return; } I know about O_DIRECT's alignment restrictions. This is why I initialize my buffer with calloc: char *buff = (char *) calloc((size_t) 1,sizeof(char)); if(write(fd,buff,(size_t)1)<1) { //Error logging free(buff); return -1; } And I get the write: Invalid

MSI SDR device sample code does not compile

蓝咒 提交于 2020-06-17 06:20:38
问题 I am trying to interface with an MSI SDR dongle, using an android app This device is a clone of the SDRPlay SDR device, and is compatible with it's software and drivers I am trying to interface with this using an OTG cable and android phone The android drivers for this can be downloaded from here https://www.sdrplay.com/downloads/ It is in the Android tab under the API/HW – V2.11 (15TH NOV 2017) link (https://www.sdrplay.com/anddl.php) A possible sample code for this driver can be found here:

Using C/C++ Library on Android

余生长醉 提交于 2020-06-15 06:16:17
问题 I have coded a library that provides some function add, sub, divide, multi by c/c++ programming language. It's built to library.so by using Android NDK. So now, I want to call these function of library by using Android. I want to as How I can do ? Thank. 回答1: NDK Package Android Studio only includes the default tools and SDK, so download and install the NDK package separately. There are two ways to do this. The first and easiest is the automatic installation option in the SDK Tools tab. This

Android NDK: no archive symbol table (run ranlib)

蓝咒 提交于 2020-06-14 06:18:57
问题 I am updating my projects to use Android ndk 16b and it was previously using 12b (was working fine). After I updated, I am running into the following error while building the final .so: /Users/ssk/code/client/git/thirdparty/android-ndk-r16b/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: jni/../../../shared-library/SharedCommon/build/arm-linux-androideabi/lib/libSharedCommon.a: no