|
Download
How to download and use BridJ (+ platform-specific notes)
Featured This page explains how to get and use BridJ using various build management systems and provides platform-specific notes, but you may want direct access to the downloads page instead.
You can try BridJ quickly through JNAerator (just select "BridJ" in the "Runtime" combobox). Get BridJIt is advised to use Maven or sbt to manage dependencies automatically. Direct downloads
Use with MavenNew releases are deployed on Maven Central, so you don't need to declare any repository : <dependencies> <dependency> <groupId>com.nativelibs4java</groupId> <artifactId>bridj</artifactId> <version>0.6.1</version> </dependency> </dependencies> If you wish to use a snapshot : <repositories>
<repository>
<id>sonatype</id>
<name>Sonatype OSS Snapshots Repository</name>
<url>http://oss.sonatype.org/content/groups/public</url>
</repository>
<repository>
<id>nativelibs4java-repo</id>
<name>NativeLibs4Java Old Snapshots Repository</name>
<url>http://nativelibs4java.sourceforge.net/maven</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.nativelibs4java</groupId>
<artifactId>bridj</artifactId>
<version>0.6.2-SNAPSHOT</version>
</dependency>
</dependencies>Use with sbtimport sbt._
class Project(info: ProjectInfo) extends DefaultProject(info)
{
// Repository for snapshots (0.6.2-SNAPSHOT onwards)
// val sonatypeSnapshotsRepo = "Sonatype OSS Snapshots Repository" at "http://oss.sonatype.org/content/groups/public"
// Repository for old releases <= 0.6
// val nativelibs4javaRepo = "NativeLibs4Java Repository" at "http://nativelibs4java.sourceforge.net/maven/"
val bridj = "com.nativelibs4java" % "bridj" % "0.6.1"
}Specialized subsets (smaller JARs !)If BridJ is too heavy for you, there are pre-packaged specialized subsets of BridJ. You can download them manually from the Maven repository or specify the correct classifier in the Maven dependency (cf. next section). List of prepackaged subsets
Build your own subsetNote that you can use the Maven Shade Plugin in your own Maven project to strip away native libraries (in the org/bridj/lib/* packages) and classes (such as COM support in org/bridj/cpp/com/*) that you don't need. Take BridJ's pom as example. Platform notesAndroidBridJ works partially on Android/arm emulators (with the SDK), and probably even on actual devices (untested). Proper C++ support might require that you compile your native library with the Android NDK r5 (or more recent) or with CrystaX's NDK, as BridJ makes some use of RTTI. See this issue for progress info. Including BridJ in a projectTo include BridJ to an Android project, you have two options :
Beware : this setting is broken in the current version of the plugin, so as a workaround you'll have to also untick the "Automatically refresh resources and assets folder on build" checkbox... Annoying ? Please let the Android devs know about it ;-)
Sample of BridJ on AndroidA simple sample of BridJ use on Android was derived from the NDK's helloworld-jni sample. It is available in BridJ's SVN repository. Building upon the NDK's helloworld-jni sample, you can modify the helloworld.c file as follows : #include <string.h>
#include <jni.h>
jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz ) {
return (*env)->NewStringUTF(env, "Hello from JNI !");
}
int addTwoInts(int a, int b) {
return a + b;
}And add the following BridJ bindings : package com.example.hellojni;
import org.bridj.*;
import org.bridj.ann.*;
@Library("hello-jni")
public class BridJLib {
static {
BridJ.register();
}
public static native int addTwoInts(int a, int b);
}You will then be able to use BridJ transparently in your activities : TextView tv = new TextView(this); int a = 10, b = 100; tv.setText(a + " + " + b + " = " + BridJLib.addTwoInts(a, b) + " (computed in BridJ-bound native function !)"); WindowsC, C++, COM support is ok. .NET support is non-existent. LinuxC, C++ support is ok. SolarisOnly Solaris x86 is supported (test hardware would be welcome !). C, C++ support is ok, with some issues in endianness-aware reading/writing with Pointer. MacOS XC, C++ support is ok. Objective-C support is dramatically undertested and probably very poor. Help would be appreciated... iOS (jailbroken iPhones and iPads)BridJ's support for iOS is not working properly yet, and relies on JamVM. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||