Questions tagged [java-native-interface]

The Java Native Interface (JNI) gives both the ability for JVM implementations to run system native code and the ability for native code to run Java code (by creating new JVM instances). The most common target languages for JNI are C and C++, for which at least the Sun/Oracle JDK implementations provide helper commands (javap - for code disassembly, javah for c code generation).

The JNI defines a standard naming and invocation convention which allows the Java virtual machine to locate and invoke native methods.

In fact, JNI is built into the Java virtual machine, allowing the Java virtual machine to invoke local system calls which perform input and output, graphics, networking, and threading operations on the host operating system.

The naming and invocation convention has been standardized by the JNI specification.

References:

9715 questions
4
votes
2 answers

JNI - Calling Java Method from C++

So I've been trying to call a java method from C++ without any luck. This is the error that I receive: JNI ERROR (app bug): accessed stale local reference 0x5cb00019 (index 6 in a table of size 2) VM aborting Fatal signal 11…
kub
  • 93
  • 1
  • 5
4
votes
2 answers

JNI - Free ByteBuffer from C++

Summary Create ByteBuffer in Java called buffer with ByteBuffer.allocateDirect(someBufferSize) Fill buffer with data Pass buffer to C++ as jobject - jbuffer Get buffer direct pointer with env->GetDirectBufferAddress(jbuffer) Work with buffer data…
Aristarhys
  • 2,092
  • 7
  • 37
  • 68
4
votes
1 answer

Calling a c++ callback from Java invoked from C++ application via JNI

I have a C++ application that needs to interface with a Java library. I'd like to receive notifications from the Java side so it needs to call back into the C++ app. I've found numerous examples on invoking Java functions from C++ (this is the easy…
GKarRacer
  • 83
  • 8
4
votes
1 answer

Using minizip with android ndk

I need to use minizip with zlib in android ndk. My jni/MyApp/Android.mk file: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := MyApp LOCAL_SRC_FILES := MyApp.cpp LOCAL_LDLIBS := -lz include $(BUILD_SHARED_LIBRARY) My…
JoniJnm
  • 720
  • 2
  • 10
  • 19
4
votes
1 answer

Best choice to represent video for iOS and Android

I am developing an app for iOS and Android to make a video call between two devices. The idea is to develop one c++ library for both platforms, and to integrate the comunication and display parts in the same way. For compatibility reasons, I am…
goe
  • 2,272
  • 1
  • 19
  • 34
4
votes
1 answer

Passing a byte array from JNI directly in Android bitmap

I have a grayscale image as a byte array in JNI, and I need to pass it to Android to be displayed on screen. At the moment my code is as follows: I copy the byte array to an int array in JNI, and then I set the pixels of the Bitmap with that…
ocramot
  • 1,361
  • 28
  • 55
4
votes
0 answers

Android error: WARN/Looper Ignoring unexpected epoll events 0x10 on wake read pipe

I'm developing a game for Android that uses a native library. In the last week or so I've been sometimes getting in my logcat a whole lot of these warnings: 01-08 13:46:20.390: WARN/Looper(6100): Ignoring unexpected epoll events 0x10 on wake read…
4
votes
1 answer

Calling java code from external native executable in Android

So here is what I want to do. I am having a third party native executable that is being spawned by my Activity. The Activity and the native executable communicate via TCP. The thing is - the third party application is using libusb and therefore…
4
votes
0 answers

Wrap a C++ Function Pointer Callback with SWIG

I'm working on porting a C++ library used in desktop and iOS applications to Android. I'm using SWIG to create the JNI code and I'm about 90% of the way to where I need to be. The only issue I have left is wrapping the callback functions from the…
Grant Limberg
  • 20,913
  • 11
  • 63
  • 84
4
votes
2 answers

Access C++ memory from Java App

I have C++ App which calls some java functionality. I'm using JNI. Everything works fine, but still there is one small problem. In C++ App I have a few huge arrays. Java App needs this data also and returns one huge array of results. Currently I…
Andrew
  • 195
  • 2
  • 9
4
votes
1 answer

callbacks in jni

Is there any way to pass a callback to java code, from C. And the call returns immediately. Later on, after completing the task, the java code can invoke that callback. I have a C extension for php that calls a java store to store some items in it.…
ata
  • 8,853
  • 8
  • 42
  • 68
4
votes
1 answer

Android NDK and C++ STL

When compiling my C++ for an iOS project, all proceeds just fine. However, I'm encountering difficulties on Android. My Application.mk reads: APP_ABI := armeabi armeabi-v7a APP_PLATFORM := android-11 APP_STL := stlport_shared All the…
Ken
  • 30,811
  • 34
  • 116
  • 155
4
votes
1 answer

Code flow in Java using JNI

I have the code on JNI level. And it can throws exceptions. The code is: #include "JavaGlueClass.h" #include #include #include jint throwNoClassDefError(JNIEnv *env, const char *message) { jclass…
amigo
  • 343
  • 5
  • 19
4
votes
1 answer

Can I use C++ exceptions in JNI library on Android?

Is there any way that I can use C++ exceptions in a JNI (Java Native Interface) library on Android? EDIT: I am talking about C++ exception handling that is entirely internal to the JNI library. That is, the exception is both thrown and catched…
4
votes
1 answer

How to expose a native enum to Java through JNI?

I am importing headers from an existing project for a port to Android-NDK. In a few cases, there are enums defined in the native headers which I would like to use from the Java layer. How can one go about doing that? Ideally, I'd like to just…
benkc
  • 3,292
  • 1
  • 28
  • 37
1 2 3
99
100