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:

9223 questions
941
votes
39 answers

Failed to load the JNI shared Library (JDK)

When I try opening Eclipse, a pop-up dialog states: Failed to load the JNI shared library "C:/JDK/bin/client/jvm.dll"`. Following this, Eclipse force closes. Here's a few points I'd like to make: I checked to see if anything exists at that…
Mxyk
  • 10,360
  • 16
  • 52
  • 75
584
votes
12 answers

How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?

How can I tell if the JVM in which my application runs is 32 bit or 64-bit? Specifically, what functions or properties I can used to detect this within the program?
BobMcGee
  • 18,846
  • 9
  • 41
  • 54
506
votes
10 answers

What is the native keyword in Java for?

While playing this puzzle (It's a Java keyword trivia game), I came across the native keyword. What is the native keyword in Java used for?
whirlwin
  • 14,425
  • 17
  • 65
  • 90
196
votes
3 answers

What makes JNI calls slow?

I know that 'crossing boundaries' when making a JNI call in Java is slow. However I want to know what is it that makes it slow? What does the underlying jvm implementation do when making a JNI call that makes it so slow?
pdeva
  • 36,445
  • 42
  • 122
  • 154
137
votes
4 answers

How to return an array from JNI to Java?

I am attempting to use the android NDK. Is there a way to return an array (in my case an int[]) created in JNI to Java? If so, please provide a quick example of the JNI function that would do this. -Thanks
RyanCheu
  • 3,350
  • 4
  • 32
  • 46
132
votes
4 answers

Eclipse reported "Failed to load JNI shared library"

I can't open Eclipse because I get an alert that says Failed to load JNI shared library C:\Program Files (x86)\eclipse\jre\bin\client\jvm.dll I've found a kind of solution on YouTube, Eclipse Failed to load JNI library fix. He says that you only…
Bocercus
  • 1,347
  • 2
  • 8
  • 3
126
votes
2 answers

How to use the same C++ code for Android and iOS?

Android with NDK has support to C/C++ code and iOS with Objective-C++ has support too, so how can I write applications with native C/C++ code shared between Android and iOS?
ademar111190
  • 13,115
  • 12
  • 74
  • 101
118
votes
10 answers

Use JNI instead of JNA to call native code?

JNA seems a fair bit easier to use to call native code compared to JNI. In what cases would you use JNI over JNA?
Marcus Leon
  • 50,921
  • 112
  • 279
  • 413
117
votes
2 answers

JNI converting jstring to char *

I have passed a URL string from Java to C code as jstring data type through the use of JNI. And my library method needs a char * as url. How can I convert jstring in char * ? P.S.: Is there any advantage of using jcharArray in C? (i.e. Passing char…
Prasham
  • 6,521
  • 8
  • 35
  • 54
107
votes
7 answers

How to bundle a native library and a JNI library inside a JAR?

The library in question is Tokyo Cabinet. I want is to have the native library, JNI library, and all Java API classes in one JAR file to avoid redistribution headaches. There seems to be an attempt at this at GitHub, but It does not include the…
Alex B
  • 75,980
  • 39
  • 193
  • 271
102
votes
15 answers

undefined reference to `__android_log_print'

What is wrong with my make file? Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := foo LOCAL_SRC_FILES := foo.c LOCAL_EXPORT_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY) foo.c #include #include…
alex2k8
  • 39,732
  • 56
  • 158
  • 214
102
votes
9 answers

How to import a class from default package

Possible Duplicate: How to access java-classes in the default-package? I am using Eclipse 3.5 and I have created a project with some package structure along with the default package. I have one class in default package - Calculations.java and I…
Michał Ziober
  • 31,576
  • 17
  • 81
  • 124
95
votes
2 answers

Calling a java method from c++ in Android

I'm trying to get a simple Java method call from C++ while Java calls native method. Here's the Java code: public class MainActivity extends Activity { private static String LIB_NAME = "name"; static { System.loadLibrary(LIB_NAME); …
Denys S.
  • 5,880
  • 12
  • 40
  • 63
95
votes
14 answers

java.lang.UnsatisfiedLinkError no *****.dll in java.library.path

How can I load a custom dll file in my web application? I've tried the following: Copied all required dlls in system32 folder and tried to load one of them in Servlet constructor System.loadLibrary Copied required dlls into tomcat_home/shared/lib…
Ketan Khairnar
  • 1,550
  • 2
  • 11
  • 19
93
votes
4 answers

How can I catch SIGSEGV (segmentation fault) and get a stack trace under JNI on Android?

I'm moving a project to the new Android Native Development Kit (i.e. JNI) and I'd like to catch SIGSEGV, should it occur (possibly also SIGILL, SIGABRT, SIGFPE) in order to present a nice crash reporting dialog, instead of (or before) what currently…
1
2 3
99 100