Where to find source code for java.lang native methods? [closed]

For JDK6 you can download the source from java.net. For java.lang the story begins at j2se/src/share/native/java/lang/, and then search… JDK7 rearranges the directory structure a little. Some methods, such as Object.hashCode, may be implemented by hotspot instead or in addition to through JNI/Java. JDK6 is freely licensed through the Java Research License (JRL) and Java … Read more

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

It is possible to create a single JAR file with all dependencies including the native JNI libraries for one or more platforms. The basic mechanism is to use System.load(File) to load the library instead of the typical System.loadLibrary(String) which searches the java.library.path system property. This method makes installation much simpler as the user does not … Read more

How to use JNI bitmap operations for helping to avoid OOM when using large images? [closed]

NOTE: this is a bit old code. for the most updated one, check out the project page on github. jni/Android.mk LOCAL_PATH := $(call my-dir) #bitmap operations module include $(CLEAR_VARS) LOCAL_MODULE := JniBitmapOperations LOCAL_SRC_FILES := JniBitmapOperations.cpp LOCAL_LDLIBS := -llog LOCAL_LDFLAGS += -ljnigraphics include $(BUILD_SHARED_LIBRARY) APP_OPTIM := debug LOCAL_CFLAGS := -g #if you need to add more … Read more

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

In order for System.loadLibrary() to work, the library (on Windows, a DLL) must be in a directory somewhere on your PATH or on a path listed in the java.library.path system property (so you can launch Java like java -Djava.library.path=/path/to/dir). Additionally, for loadLibrary(), you specify the base name of the library, without the .dll at the … Read more

How to fix an UnsatisfiedLinkError (Can’t find dependent libraries) in a JNI project

I’m pretty sure the classpath and the shared library search path have little to do with each other. According to The JNI Book (which admittedly is old), on Windows if you do not use the java.library.path system property, the DLL needs to be in the current working directory or in a directory listed in the … Read more

What is the native keyword in Java for?

Minimal runnable example Main.java public class Main { public native int square(int i); public static void main(String[] args) { System.loadLibrary(“Main”); System.out.println(new Main().square(2)); } } Main.c #include <jni.h> #include “Main.h” JNIEXPORT jint JNICALL Java_Main_square( JNIEnv *env, jobject obj, jint i) { return i * i; } Compile and run: sudo apt-get install build-essential openjdk-7-jdk export JAVA_HOME=’/usr/lib/jvm/java-7-openjdk-amd64′ … Read more