FAQ Database Discussion Community


Implementation of C in JNI , syntax changing

c,jni
One thing that confused me from JNI tutorial website is the changing of C syntax. Do I have to rewrite this /* helloworld without JNI implementation */ #include <stdio.h> void main() { printf("Hello world\n"); return; } into this /* JNI implementation - HelloJNI.c */ #include "HelloWorld.h" #include "jni.h" #include "stdio.h"...

java jni transfer coordinates from c to java [closed]

java,c,arrays,jni
i will get straight to question. I have facedetection done in c with .dll libraries using jni. I send stream array from java to c. I am successful on getting coordinates of the face (4 points), how do I transfer those coordinates from C back to java? These coordinates are...

Is there any way to get actual type from a string value?

c,jni
I'm learning the C programming language. Is there any good/reasonable way to get the actual type from a string value? I already heard the sizeof operator is almost a compile-time thing. Say we have the following string literal which may be provided in runtime. char *name_of_long_long_int = "long long int";...

make native code access java methods and data members

java,android,c++,android-ndk,jni
I am working on an android project with native code that is supposed to update a List and some other boolean variables in an object. consider the following code some java class in my code looks like: class ReturnObject { boolean a, b; public List<String[]> listA; } public class foo...

How to replace cocos2d-x scene from Java?

java,android,jni,cocos2d-x
I want to replace the scene in a cocos2d project from Java. I created the following JNI methods: void cocos_android_app_init (JNIEnv* env, jobject thiz) { LOGD("cocos_android_app_init"); AppDelegate *pAppDelegate = new AppDelegate(); } extern "C" { JNIEXPORT void JNICALL Java_com_example_myapp_MainActivity_changeScene( JNIEnv* env, jobject thiz){ cocos2d::Scene* scene = MyScene::createScene(); Director::getInstance()->replaceScene( TransitionFade::create( 1,...

convert std::string to jstring encoded using windows-1256

c++,jni,stdstring
I am using a library (libcurl) that requests a certain webpage with some Arabic content. when I obtain the string response it has Arabic characters and the whole response is encoded in WINDOWS-1256. the problem is arabic chars dont show up properly. is there a way to convert an std::string...

CallXXXMethod undefined using JNI in C

java,c,jni
So I've tried to use the JNI interface to call Java methods from C. Calling static methods is no problem, but I get stuck when I want to call a method on an object. The code is as follows: #include <stdio.h> #include <string.h> #include <jni.h> int main() { JavaVMOption options[1];...

NewGlobalRef/DeleteGlobalRef when returning object created in JNI

java,android-ndk,jni
When returning reference to object created in JNI method to Java, should we return result of NewGlobalRef call on created object? And, respectively, later, when object no more required in Java, do we need to call JNI method to do DeleteGlobalRef on the reference passed from Java? Or NewGlobalRef/DeleteGlobalRef required...

onManagerConnected status returning value 2 [Market error]

java,android,opencv,jni,opencv4android
public class MainActivity2 extends ActionBarActivity { private static final String TAG = "Test Opencv Loadback"; public static String imgPath; private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { Log.i(TAG, "OpenCV loaded successfully"); } break; default: { super.onManagerConnected(status); } break;...

Win64 - JNI: UnsatisfiedLinkError: Can't find dependent libraries

java,dll,jni,unsatisfiedlinkerror,win64
I have a own JNI dll which depends on a few other dlls (Zero MQ to be precise). I have compiled these dependencies on Windows 7(64bit) via Visual Studio. I defined that I get 64-bit dlls. On the developer machine it works just fine. But if I move those dlls...

issues in creating c linux library

java,c,openssl,jni,shared-libraries
Hi I am creating an openssl wrapper c library to be use with JNI. My c source file name is rsa.c and JNI header file name is OpensslRSA.h which is contain in both JAVA_HOME/include and JAVA_HOME/include/linux directories. I am using below syntax to create this library . gcc -shared -fpic...

Getting Android Bluetooth Adapter Name from JNI/C++

android,c++,bluetooth,android-ndk,jni
The Android API in question is android.bluetooth.BluetoothAdapter, which has a member function getName() which returns the adapter's user friendly name. In java: BluetoothAdapter.getDefaultAdapter().getName() I know I can wrap this in a java-function, which I call through jni, but, how can I achieve the same in C++, with only jni/android-ndk?...

Is there any chance the sizeof operator returns 0?

c,jni,sizeof
I require to return a value of sizeof(some_t) from C to Java. JNIEXPORT jint JNICALL blar(blar) { #ifndef some_t return ?; #else return sizeof(some_t); #endif As you can see I must return some value for the case the type is not even defined. So what's the best value for that...

APK size exceed 50MB due to large amount of native libraries

java,android,jni,apk,native
Our app supports 7 different architectures. We have a native library which we are using in our java code. When we build a single APK its size reach the 50MB limit because we have 7 instances of the native library packed into the APK. Each instance of the library after...

How to set a field from C++ to Java, using JNI

java,c++,jni
I have a java class: public class LibClass { public static String receivedValue; ...native methods... } Then in the c++ code, I want to set the value of the String from C++. I don't want to create new objects, I just want to assign a value to the String. In...

Need to understand Andorid.mk better

jni,android.mk
I have read all the Android.mk intro, and reviewed a number of posts on it here on this forum. And still am not sure how to apply it to what I am trying to do. I am just trying to have access to native library files some of which are...

ReleaseStringUTFChars not working for std::string

c++,jni,stdstring
I use std::string in my jni function, and I fail to release it using ReleaseStringUTFChars. The error I get is: error: no matching function for call to NIEnv::ReleaseStringUTF env->ReleaseStringUTFChars(path, dir); I understand, that instead of string, the function expects to get char, but I don't have such variable. What should...

JVM Embedded into C, does not appear under running programs

java,jvm,jni
I have a C program (working in Solaris SPARC), which is creating a JVM and calling a Java application via JNI. The JVM is created and the java program works as expected, but I don't see the java process with ps -ef | grep java command. Any idea about what...

setPreviewSize doesn't work propertly only in some devices

android,opencv,camera,jni,android-camera
I'm developing a application using OpenCV native, and opening the camera in Java. My app works propertly in a MotoG, but when I use other devices, it fails. My preview callback send the image and I got this Error: E/Camera-JNI(22013): Callback buffer was too small! Expected 3110400 bytes, but got...

Android NDK and Gradle: Different Android.mk per build type

android,android-studio,android-ndk,jni,android-gradle
My native library contains logs which I would like to remove at compile time. Logs are shown by defining the pre-processor macro ENABLE_DEBUG in LOCAL_CFLAGS like so: include $(CLEAR_VARS) LOCAL_MODULE := native-stuff LOCAL_SRC_FILES := Native.cpp LOCAL_LDLIBS := -llog LOCAL_CFLAGS := -DENABLE_DEBUG include $(BUILD_SHARED_LIBRARY) I'm building the app with Gradle via...

Android (ART) crash with error JNI DETECTED ERROR IN APPLICATION: jarray is an invalid stack indirect reference table or invalid reference

java,android,android-ndk,jni,leptonica
I am writing an Android application that processes a picture from the native C (NDK r10d). The code was working well until recent ART introduction that is more strict with JNI. So the code is working fine with Dalvik (e.g. on pre-Lolipop devices) but ii creates a SIGENV on...

does NewDirectByteBuffer create a copy in native code

java,c++,jni,native
I am creating two arrays in c++ which will be read in java side: env->NewDirectByteBuffer env->NewByteArray does those functions copy the buffer I send it? Do I need to create the buffer on the heap in the c++ side or is it ok to create it on the stack because...

AES_encrypt/AES_decrypt only returns part of a message

openssl,jni
I don't know why the following code will return "Hello native! Th" not "Hello native! This is from jni load!\n", may someone tip it? #include "helloJNI.h" #include "openssl/aes.h" #define LEN 1024 jstring jni_text(JNIEnv *env, jclass clz) { AES_KEY aesKey; int result; const char origin[] = "Hello native! This is from...

C++ DLL does not run on different machine

c++,visual-c++,jni
I am developing a simple c++ application to generate a dll which later I am using in JNI to run native api calls, but the thing is the dll works well on the machine which I used to develop the dll but does not on the server. Both machines run...

DCIM directory path on Android - Return Value

android,c++,android-ndk,jni
I have requirement of getting DCIM directory path from Native code. I am using the following code snippet: jclass envClass = env->FindClass("android/os/Environment"); char charParam[] = "Environment.DIRECTORY_DCIM"; jstring jstrParam = env->NewStringUTF(charParam); jmethodID getExtStorageDirectoryMethod = env->GetStaticMethodID(envClass, "getExternalStoragePublicDirectory", "(Ljava/lang/String;)Ljava/io/File;"); jobject extStorageFile = env->CallStaticObjectMethod(envClass, getExtStorageDirectoryMethod, jstrParam); jclass...

Android Studio NDK return jint

android,android-ndk,jni,jint
I have successfully followed this tutorial https://www.youtube.com/watch?v=kFtxo7rr2HQ to learn about building NDK apps with Android Studio. That tutorial uses a public native String HelloJNI(); That string is set in the HelloJNI.c file #include "com_example_myapplication_MainActivity.h" /* Header for class com_example_myapplication_MainActivity */ /* * Class: com_example_myapplication_MainActivity * Method: HelloJNI * Signature: ()Ljava/lang/String;...

Is providing an implementation for all native methods required?

java,android,jni
Couldn't find this via a quick google search on "java unimplemented native methods" and the question title. Several sources say you must provide an implementation, but then they go on to call the function they've implemented, so it's kinda logical that they need a separate implementation. My question has a...

allocation and deallocation problems in JNI Android

android,c,jni
I ve been trying to use a C library for convolution of two wav files under Android. I always get empty outputs. I tried to track down the problem, and i noticed that the arrays were not allocated properly. Here's the code: int transform(double real[], double imag[], size_t n) {...

java.lang.UnsatisfiedLinkError when using JNI on ubuntu

java,jni
java.lang.UnsatisfiedLinkError when using JNI. My Testing Environment: Ubuntu 12.04/64-bit JDK 1.7 gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) This is my java source: public class HelloJNI { static { //System.loadLibrary("libHelloJNI"); } private native void sayHello() ; public static void main(String[] args){ //System.getProperties().list(System.out); String lib_path = System.getProperty("java.library.path"); System.out.println("java.library.path=" + lib_path); System.loadLibrary("libHelloJNI"); HelloJNI myJNI = new...

Calling simple java static method via JNI does not work, though c++ compiles and run it

android,c++,qt,jni,qtandroidextras
Considering this Java class with the static method: public class TestClass{ public string str; public TestClass() { str = "Test From Java"; } public static String staticMethod() { return "Test From Java"; } } I have written these lines of code in c++ file: QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod( "org/.../TestClass" ,"staticMethod"...

Deploying JRE via JNI: jvm.dll not designed to run on Windows or […]

java,c++,jvm,jni
So I'm creating a Win32 application that packages the Java Runtime Environment (JRE) as a resource. The application extracts the resource to the disk and unzips it. Now, I would like to use this JRE in order to run a Java program using the invocation API. As soon as I...

SIGSEGV when calling Java method from native pthread

java,c,multithreading,jni,pthreads
In a Java project that uses C code via JNI I have a piece of native C code that obtains references to an object and one of its methods, then starts a native thread, passing these references to it in a struct. When the thread tries to call the method,...

CallObjectMethod does not return a string

java,c++,jni
My aim is to create an instance of a Java class in C++, and then call methods defined in the Java class. Here is a summary of my Java class : EXICodec.java public class EXICodec { ... private static String inputXML; ... public EXICodec() { System.out.println("Constructor"); this.inputXML = "string"; ......

Klocwork plugin failed to run in eclipse with error “java.lang.UnsatisfiedLinkError: no sqlite_jni in java.library.path”

eclipse,sqlite,eclipse-plugin,jni,klocwork
I just installed Klocwork plugin for Eclipse. But when I start to scan a project, it gives me the following error: java.lang.UnsatisfiedLinkError: no sqlite_jni in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at com.klocwork.desktopdb.SqliteJniLoader.initDefaultLibraries(SqliteJniLoader.java:28) at com.klocwork.desktopdb.SqliteAgent.<clinit>(SqliteAgent.java:21) at...

Error when calling Native Code using JNI from a Jython module

eclipse,jni,jython
I am calling a simple HelloWorld program written in C from a Jython module (inside a PyDev project). There is an intermediate Java Class (in a separate Java project) which calls the native code using JNI (Java Native Interface). The native call is successful if I run the Java class...

How to return double[] in jni input argument

java,c++,arrays,jni,arguments
In my Java code I have defined the following function signature: public native boolean getData( double [] data ); In my C++ code I'd like to populate the double array data to return back to Java, and the returned boolean from the function will indicate whether the data was set...

JNA causes UnsatisfiedLinkException with Unix Stat

java,c,linux,jni,jna
So, I'm attempting to call the Linux C - stat function. My JNA code: public int stat(bap path, bap statdump); the bap class: public static class bap extends Structure { public byte[] array; public bap(int size) { array = new byte[size]; } @Override protected List getFieldOrder() { return Arrays.asList(new String[]{"array"});...

Loading dll using loadLibrary

java,jni,64bit,environment-variables
I am currently maintaining a Java communication library which wraps the functionality offered by some dll via JNI. At some point, in Java, I need to load the JNI wrapper to forward my requests and finally call the native library. Currently, this is accomplished by calling System.loadLibrary("MyLibrary"); As stated here,...

Overload JNI Method

java,jni,overloading
I have an existing JNI method with two parameters. Been around for a while, in use, so I don't want to just change it lest the wrath of angry customers be unleashed. But, I now need to make an adjustment. So, I thought, make a second overloaded method with the...

Android JNI bridge Toast C++ not working - How to fix it?

c++,delphi,jni,c++builder,c++builder-xe7
I'm trying to solve a little problem with my hpp unit. I found some examples on the internet showing how to Toast an information on screen with an Android JNI bridge, but it was just in pascal (delphi), so I decided to use the same pas file but with it...

using i686-w64-mingw32-g++ for static libraries

static,jni
I have a JNI project, which I have to make work on Windows (I am working on Linux). This project actually depends on third-party library file which is static (archived i.e .a files). I am trying to create a JNI shared library file using i686-w64-mingw32-g++ and including -static followed by...

JavaH failing to create C header file for JNI class

java,c++,class,jni,jna
This is really baffling me as I have tried everything possible with regards to classpath and various other things. I have tried from various different commands prompts in windows, linux and IDEs but nothing seems to help. Always the same error. Any insight would help here. I am getting the...

What is the best way to save JNIEnv*

android,android-ndk,jni,jnienv
I have an Android project with JNI. In the CPP file which implements a listener class, there is a callback x() . When x() function is called, I want to call another function in a java class. However, in order to invoke that java function, I need to access JNIEnv*....

Calling Collections.sort via JNI

java,c,linux,jni
I am working on a JNI implementation using C and try to sort a list of type java/lang/List using java/util/Collections sort method with a Comparator. To get the descriptor signatures I mainly use javap. In this case javap does not show any descriptor for the sort methods. All I get...

ejdb Java binding not working “no jejdb in java.library.path”

java,jni,ejdb
I'm trying to get the java binding of ejdb (http://ejdb.org/) to work. The bindings can be found on Github: https://github.com/Softmotions/ejdb-java The binding can be build via the usual ./configure && make && make install step. The result is a libjejdb.so file in the target directory and a java library. Running...

Undefined reference for JNI methods

jni
I'm trying to use JNI with an existing C library. When I try to generate the .so file using this command: gcc -shared -fpic -o libWrapper.so -I/usr/lib/jvm/java-1.7.0-openjdk-i386/include/ -I/usr/lib/jvm/java-1.7.0-openjdk-i386/include/linux/ -I/home/testdpdk/packet-pro/dpdk-2.0.0/i686-native-linuxapp-gcc/include Wrapper.c -Wl,-z,defs I get errors to do with undefined references for the methods which are included with the JNI: /tmp/ccyrfz1B.o: In...

How to pass a structure as an argument to java function or return to java from jni

java,android,c,android-ndk,jni
I have two questions Say I have some structure in jni say struct X { Type_A x; Type_B y; } Now how do I? Pass this structure as an argument to a java call back function How do I return this structure to a Java function. If possible, please give...

Can't find OpenCV headers when compiling with ndk-build

android,opencv,android-ndk,jni
When I try and ndk-build my project, I get: opencv/core/core.hpp: No such file or directory #include <opencv/core/core.hpp> ^ As far as I can see, I've got everything configured correctly: Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # OpenCV OPENCVROOT:= /.../ OPENCV_CAMERA_MODULES:=on OPENCV_INSTALL_MODULES:=on include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk LOCAL_MODULE := native_lib LOCAL_SRC_FILES := jni_part.cpp...

Opencv in android studio does not work?

java,android,opencv,android-ndk,jni
I'm trying to add native code to my Android app. NDK worked fine with simple C++ code like "Hello from C++", but I need to use openCV, and I am stuck. Project build output: :app:generateArmDebugSources UP-TO-DATE :app:compileArmDebugJava UP-TO-DATE :app:compileArmDebugNdk D:/android-ndk-r10c/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:...

How can I assign the NULL to a float/double variable?

c,jni
I have a problem using JNI. jboolean z = (jboolean) NULL; // ok jbyte b = (jbyte) NULL; // ok jchar c = (jchar) NULL; // ok jshort s = (jshort) NULL; // ok jint i = (jint) NULL; // ok jlong j = (jlong) NULL; // ok jobject l...

NoSuchMethodError in JNI to Java Exception

java,android,exception,jni,nosuchmethoderror
I am getting this error: java.lang.NoSuchMethodError: no non-static method "Ljava/lang/AssertionError;.(Ljava/lang/String;)V" jclass clazz = env->FindClass( "java/lang/AssertionError" ); env->ThrowNew( clazz, "Test Assertion" ); Note: env is JNIEnv* Any thoughts? I see that AssertionError exists. I am seeing this on Android Lollipop only. It seems to be fine on android 4.4.2. ...

How to free memory allocated by native method on Java side?

java,c++,memory-leaks,jni,native
I am trying to pass a byte array (with random data) from native to Java and I am not sure if this causes any memory leak or not. Here's the C++ code. JNIEXPORT jbyteArray JNICALL Java_com_sample_test_jni_TestJNI_return_1byte_1array (JNIEnv *env, jobject obj) { unsigned char *byteArray = new unsigned char[LENGTH]; srand(12345); for(int...

When to use CallNonvirtualObjectMethod and its related methods?

java,c++,jni
It seems like CallStaticObjectMethod, CallObjectMethodMethod and etc... are all you need. According to the docs CallNonvirtual<type>Method families of routines and the Call<type>Method families of routines are different. Call<type>Method routines invoke the method based on the class of the object, while CallNonvirtual<type>Method routines invoke the method based on the class, designated...

JNI method Executed automatically

java,android,jni
I have a JNI method as following: JNIEXPORT void JNICALL Java_com_test_Test_finalize (JNIEnv *env, jobject self) { LOGD("finalize TID:%d", gettid()); // write out the trailer and clean up _finalize(br_ctx); } The method in java Test class: public native void finalize(); I'm sure that there is one place to invoke Test#finalize(): private...

Get length of jstring/char *?

java,c++,c,jni
This is my JNI C code: JNIEXPORT jint JNICALL Java_org_avuna_httpd_util_CLibJNI_bind(JNIEnv * this, jclass cls, jint sockfd, jint family, jstring path, jint len) { struct sockaddr_un sun; sun.sun_family = family; const char *npath = (*this)->GetStringUTFChars(this, path, 0); sun.sun_path = npath; return bind(sockfd, sun, sizeof(&npath)); } I just guessed unsuccessfully (sizeof(&npath)) how...

call main method in java module using JNI

java,c,jni
I've been trying to call the main method of a class and pass it some arguments. My code is as below: args = (*env)->NewObjectArray(env, 2, myClass, NULL); arg1 = (*env)->NewStringUTF(env, "Hello"); arg2 = (*env)->NewStringUTF(env, World!"); (*env)->SetObjectArrayElement(env, args, 0, arg1); (*env)->SetObjectArrayElement(env, args, 1, arg2); (*env)->CallStaticVoidMethod(env, myClass, mainMethod, args); But it seems...

android jni return multiple variables

java,android,jni
How to return multiple variables from jni function, avoiding the overhead of an array mangaling?

Calling Rust from Java

java,jni,rust
I am using Rust 1.0 beta and was able to create a small example for calling functions written in Rust from Java. I simply compiled the following Rust code in mylib.rs using rustc which produces a mylib.dll on Windows: #![crate_type = "dylib"] use std::any::Any; #[no_mangle] pub extern fn Java_tests_Test_hello(env: *const...

Qt does not compile callStaticObjectMethod() it says no matching function to call for

c++,qt,jni,qtandroidextras
I wrote the following code from this question and it was complied and worked perfect: QAndroidJniObject str = QAndroidJniObject::callStaticObjectMethod<jstring>( "org/.../TestClass" ,"staticMethod"); Now I have changed the java method and it needs an input parameter of type string. The Java code: public class TestClass{ public string str; public TestClass() { str...

Embed shared libs in Java Applets

java,deployment,applet,jni
Is it possible to embed linux shared libs (.so) in Java applets? I know that I can call JNI code from applets (privileged only), but is it possible embed these libs inside the applet?...

java.lang.UnsatisfiedLinkError: org.thotheolh.jche.NativeBridge.loadPKCS11Module(Ljava/lang/String;)V

java,jni
I have looked through the UnsatisfiedLinkError helps in StackOverFlow and other search engines but the solutions have not satisfied the problem so I will state them here. I am trying to make a JNI call to a PKCS11 DLL library and I am getting the following error: Exception in thread...

JNI cache java array

java,c++,arrays,jni
I have a java application and some native c++ code. The java application runs some threads. Each thread has an array of double which is passed as parameter to the native code. So far everything works well. Now in my native code, I want to write values in the array....

Call NewObject method jni with params in jobjectarray

java,c++,jni
I am working in JNI with c++ and I have created a method where a series of parameters are passed to my native method as a jobjectarray. I would like to call a constructor in JNI using those parameters. However the NewObject method does not accept a jobject array instead...

Linking library and undefined reference to function in JNI

java,android,jni,shared-libraries,static-linking
I'm trying to use two different libraries in my JNI code: I've tried to compile them with the following android.mk file: TOP_PATH := $(call my-dir) # Lib native-audio-jni #------------------------------------------------------------------------------------------------------ APP_PLATFORM := android-19 LOCAL_PATH := $(TOP_PATH) include $(CLEAR_VARS) LOCAL_MODULE := native-audio-jni LOCAL_SRC_FILES := native-audio-jni.c \ wavfile.c # for native audio LOCAL_LDLIBS...

How does NDK work in Android - What is the order that NDK, JNI etc are used?

java,android,android-ndk,jvm,jni
How are: Java, NDK, JNI, JVM, C/C++ code etc. related to each other in an android project? I want to know what happens e.g. Java code runs NDK method, NDK uses JNI library or whatever happens. Also what is the difference between NDK and JNI Sorry if this question is...

When did the Dalvik JNI start supporting pinning?

java,android,jni,dalvik
The Android NDK appears to support pinning down Java objects accessed from native code using GetByteArrayElements and friends. But how long has this been the case? In other words, will my app avoid copying when possible on older devices too?

Can't understand this UnsatisfiedLinkError

java,jni
Getting this exception when creating a java wrapper for C SDL library: Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sdl4j.renderer.SDL_Renderer.SDL_CreateRenderer(Lcom/sdl4j/window/SDL_Window;II)Lcom/sdl4j/renderer/SDL_Renderer; Java Caller (1st method completes fine and looks 100% similar on both java/c++ sides): SDL_Window win = SDL_CreateWindow("Hello World!", 0, 0, 1024, 768, SDL_WindowFlags.SDL_WINDOW_SHOWN); SDL_Renderer ren = SDL_CreateRenderer(win, -1, SDL_RendererFlags.SDL_RENDERER_ACCELERATED |...

How can I pass a struct to a kernel in JCuda

java,struct,cuda,jni,jcuda
I have already looked at this http://www.javacodegeeks.com/2011/10/gpgpu-with-jcuda-good-bad-and-ugly.html which says I must modify my kernel to take only single dimensional arrays. However I refuse to believe that it is impossible to create a struct and copy it to device memory in JCuda. I would imagine the usual implementation would be to...

Error in VS2010 when trying to compile basic JNI Test Code

java,c++,visual-studio-2010,jni
I am trying to compile a basic JNI Test in preparation for a DLL (with headers and lib file) I am expecting to receive in the next few days that I will need to create a JNI interface for. I have tried pointing it to the x64/x86 lib of JNI.lib....

Qt for Android - startActivityForResult equivalent does not work

java,android,qt,android-intent,jni
There are poorly documented features in Qt for Android - we can use Intent features by JNI (Java Native Interface). There are some examples with startActivity equivalent, but I did not find any with result receiving. Here's Java code with ilustration what I want to do: Intent intent = new...

JNI C++ to Java 32 bit image not showing properly

java,c++,colors,bitmap,jni
I have the following C++ code for JNI And the following Java code to create a 32bit bufferedimage, the sizes are also received through JNI Everything seems to work only that I have some weird colors in the image and I don't know how to get it right Result of...

will cache jclass in native code prevent the class been unloaded

java,android,jni
according to http://developer.android.com/intl/zh-tw/training/articles/perf-jni.html The class references, field IDs, and method IDs are guaranteed valid until the class is unloaded. Classes are only unloaded if all classes associated with a ClassLoader can be garbage collected if I keep a global reference of the class, will it guarantee the class never been...

NDK - include error

android,android-ndk,jni
I need your help because it drives me crazy. What cause my error? The error is "jni/algorithm.cpp:4:33: fatal error: opencv2/core/core.hpp: No such file or directory #include <opencv2/core/core.hpp> ^ compilation terminated. make: *** [obj/local/arm64-v8a/objs/algorithm/algorithm.o] Error 1" My algorithm.cpp is: #include <jni.h> #include <string.h> #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/features2d/features2d.hpp> #include "opencv2/highgui/highgui.hpp"...

Must I DeleteLocalRef an object I have called NewGlobalRef on?

java,jni
As we know, creating Java objects in a thread owned by C/C++ we are responsible to call DeleteLocalRef or Push/Pop LocalFrame as needed. I have some code like jbyteArray buffer = env->NewByteArray((jsize)requiredSize); longTermBufferReference = (jbyteArray)env->NewGlobalRef(buffer); where native code creates a byte array, which it re-uses across multiple threads/calls, once we...

Java native library architecture depend on JVM or OS?

java,jni
I want to load native library to Java program, which is fine but I don't know which architecture should I load. If I'm running on x64 and I have a x64 JVM I will load 64 bit library but If I will run on x86 JVM on x64 what I...

Can I cast native primitive type into a JNI primitive type without worrying about endianness?

c,jni
Let's say I have const uint16_t n = 0x0001; Then can I cast like this? const jint j = (jint) n; Without worrying about endianness of the native platform? Supplement I have a function changes a value into an char array. char * value_to_array(void * value, const size_t size) {...

Return a big object array from JNI?

jni,jnienv
According to the doc jint EnsureLocalCapacity(JNIEnv *env, jint capacity); Ensures that at least a given number of local references can be created in the current thread. Returns 0 on success; otherwise returns a negative number and throws an OutOfMemoryError. Before it enters a native method, the VM automatically ensures that...

Are jfieldID and jmethodID bound to the specific class or can I use them on subclass objects?

java,jni
When I calculate a field ID (or method ID) with env->GetFieldID(superClass, name, descriptor) (or env->GetMethodID(superClass, method, descriptor)), can I use the same ID on objects of type subClass (which inherits from superClass)?

How do you add APP_CFLAGS to an android makefile

android-studio,makefile,jni,make
I was able to successfully pass in APP_CFLAGS via eclipse through via the settings' ndk-build command as ndk-build -B NDK_DEBUG=1 APP_CFLAGS=-DTEST I have now switched to Android studio and was trying to do it directly in the makefile with the following, but its not taking: LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS)...

JNI libraries deallocate memory upon garbage collection?

java,garbage-collection,jni,jcuda
I am using JCUDA and would like to know if the JNI objects are smart enough to deallocate when they are garbage collected? I can understand why this may not work in all situations, but I know it will work in my situation, so my followup question is: how can...

I receive error message when run JNI android app A/libc﹕ Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 17729

java,android,c++,jni,native
I got an error when i run android app that I use JNI functions and c++ code in it. When it run, I got below message: Fatal signal 11 (SIGSEGV) at 0xe480001d (code=1), thread 5465 And finally here is my codes: JNIEXPORT jstring JNICALL Java_ir_bassir_ndktest4_MainActivity_getName (JNIEnv *env, jobject obj){ jclass...

Can not add all the classes files from the JNI folder in Eclipse (JAVA, Windows 7)

java,eclipse,dll,jni
I have a classes directory "JNA" contains follwing .class files : MClass.class SClass$SC_PROC.class SClass$S_PROC.class SClass.class and then I tried to add this directory in my current project : Java Build Path -> Add external class folder -> class (JNA)folder path -> ok After this eclipse only adds two .class files...

error while loading shared libraries: libjvm.so:

jni
I am trying to make this JNI example works. I am able to compile all the files but I can not launch the executable because of this error : ./TEST: error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory I have checked all...

Java compilation error : /bin/ld:cannot find -ljvm

java,linux,gcc,jni,fuse
I am trying to build a java project http://sourceforge.net/projects/fuse-j/?source=typ_redirect on fedora machine. The compilation fails while compiling JNI bindings. MakeFile include ../build.conf include ../jvm_ldpath.def SRCS := javafs.c javafs_bindings.c HDRS := javafs.h javafs_bindings.h LIB_SO := libjavafs.so INCLUDES := -I${FUSE_HOME}/include -I${JDK_HOME}/include -I${JDK_HOME}/include/linux LDPATH := ${LDPATH} -L${FUSE_HOME}/lib all: ${LIB_SO} ${LIB_SO}: ${SRCS} ${HDRS} gcc...

Does jni::ExceptionDescribe implicitily clear the exception trace of the JNI environment object?

java,c++,exception-handling,jvm,jni
I tried to implement some kind of exception handling At first i called jni::ExceptionDescribe() after that i used the implementation of How to obtain a description of a Java exception in C++ when using JNI? which i just named for simplicity printStackTrace()and which completely works fine . My problem is...

Cannot convert 'const bool' to 'jobject

c++,hashmap,jni
I need to add a bool to an object map, my bool is defined as a primitive, and I need to convert it to an object. How do I do that ?...

Sending jbyte array to Java method failed using JNI

c++,qt,jni,qtandroidextras,jbytearray
Consider this java method: public int write(byte[] src, int timeoutMillis) throws IOException { System.out.println("Write function started."); System.out.println("buffer = " + src.length); System.out.println("buffer = " + src[0]); return 1; } I tried to use this method from c++ using Qandroid JNI. Here is the code I've written in c++: jbyteArray buffer...

How to synchronize on java object in c++ passed from java to c++?

java,c++,multithreading,jni
Am passing a java object to cpp. I want to synchronize on that java object in cpp. (I want to synchronize on the same object in java side also, but no problem with this since this can be easily achieved thru synchronized block). Goal is: cpp will put keep on...

Why does creating a C++11 thread cause a Fatal Signal?

android,multithreading,c++11,android-ndk,jni
I want to create a C++11 thread that runs indefinitely, after a JNI call has been made. Why does this generate a Fatal Signal? #include <thread> static void teste() { while(true) LOGI("IN TEST"); } JNIEXPORT void Java_blahblah(JNIEnv *javaEnvironment, jobject self) { std::thread t(teste); //t.join(); //I don't want to join it...

Call native library method in independent native library

android,c,android-ndk,jni
I am trying to implement the solution stated in this stackoverflow post. As the solution suggests, I created a independent native library. This how I have implemented that library thus far. #include "zoom_Main_VideoPlayer.h" #include <dlfcn.h> void *handle; typedef int (*func)(int); // define function prototype func myFunctionName; // some name for...

Is manually freeing resources of JNI method id required

java,jni
I'm learning JNI and I found that jmethodID is actually a pointer. Do I need to manually free the pointer that is returned by GetMethodID()?...

Accessed stale local reference passing short[] from JNI to Java

java,android,callback,jni
Hello I'm writing a program for Android with Java and JNI. I'm caching JavaVM*, a global ref jclass and 2 methodsID in the onLoad(). Then from myCallback(), which is running on a separate thread, I get the ref to the environment using AttachCurrentThread() and the cashed JavaVM*. Then I want...

Generating scip.jar file (mac)

jni,gmp,scip
So I got the scip suit from here and makeed it. Then I went to scipoptsuite-3.1.1/scip-3.1.1/interfaces/jni and followed the instructions in the README: 1) doxygen jniinterface.dxy - generates xml documentation 2) ./createJniInterface.py xml/* - uses the xml documentation and creates JNI interface 3) create softlinks to soplex and scip in...

JNI to running process instead of using a library [closed]

java,c++,opencv,jni
I have some image recognition software running to generate input for my game. I detect movements through openCV in C++, however a constraint is that the game itself should be written in java.I would like to query the state of the openCV process to get some objects for input. I...

How to manipulate CameraPreview bytearray through the JNI? (OpenCV)

java,android,c++,opencv,jni
inside my "public void onPreviewFrame(byte[] data, Camera camera) { .... }" I want to take the bytearray "data" and pass it to the JNI and apply some OpenCV filters so that the preview changes, without returning it. What is the best way to do this? Currently I only pass the...

A resource was acquired at attached stack trace but never released. memory leak

java,android,memory-leaks,android-ndk,jni
If I comment out the method (*a)->CallVoidMethod(a, b, meth, "FROM JNI"); The app doesn't crash else it crashes. Assuming that I haven't released the resource "jstr" which might have caused a memory leak then why does it happen only when CallVoidMethod() ? What should I do to solve this issue?...

JNI UnsatisfiedLink Error

java,c,netbeans,jni,native-methods
So I'm new to JNI and I'm following a simple hello word example but I keep getting error UnsatisfiedLinkError. What am I doing wrong? Here's my .h file: /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class JNITEST_jnihellonative */ #ifndef _Included_JNITEST_jnihellonative...

Set IplImage from object Bitmap and get result from IplImage to be a jIntArray

android,c++,opencv,jni,iplimage
I am working on android / JNI / Opencv. I need to read a jObject set to be a Bitmap, send it to be an IplImage * inside a function then the output will be converted back to jintArray. This is my code: JNIEXPORT void JNICALL Java_com_cs_here_there_nProcessOnBitmap(JNIEnv* env, jobject thiz,...

How do i call C/C++ code from Android using JNA?

android,c++,android-ndk,jni,jna
I'm trying to integrate this specific library to my Android project, and the library is written in C/C++. I've miraculously gotten ndk-build to give me the needed .so file. However, looking at it, there's a sample in the project, and they use a mysterious .jar with the API bindings of...

JVMTI - Get object for field in class

java,oracle,jvm,jni,jvmti
I'm having a problem with JVMTI. I would like to access each static field of a class and tag it. I can get the signature of each field, I can find out if it is static, but I haven't found a method yet to get a jobject for the fields...