I try to create an OSGi bundle using native C/C++ code for deployment on an Android device running Felix.
I was able to compile the native code and link it to a shared object using the Android NDK arm-linux-androideabi toolchain.
Now, I try to export the OSGi bundle to a .jar file using eclipse PDE (Export->Deployable plug-ins and fragments). This fails. The error-window popping up tells me:
'Export Plug-ins' has encountered a problem.
Processing inclusion from feature org.eclipse.pde.container.feature: Bundle my.bundle.jni_test_1.0.0.qualifier failed to resolve:
Unsatisfied native code filter: natives/libjni_example.so; processor=arm; osname=linux.
When setting processor to something other (like x86), the export works but I get an "Unresolved constraint" error in the bundle when starting it on my Android device.
I hope, I'm not doing something completely silly. Has anyone an idea, what is going wrong here? How can I add native code compiled for Android to an OSGi bundle?
For completeness, I attach the Java, C, Manifest and build.properties content:
Java -> JNI_Test:
package my.bundle.jni_test;
public class JNI_Test {
private void doWork() {
System.out.println("3+3=" + add(3,3));
}
static {
System.loadLibrary("jni_example");
}
public final static native int add(int x, int y);
}
C -> jni_example:
#include "include/my_bundle_jni_0005ftest_JNI_0005fTest.h"
#include <stdio.h>
JNIEXPORT jint JNICALL Java_my_bundle_jni_1test_JNI_1Test_add(JNIEnv *env, jclass clazz, jint x, jint y) {
char buf[100];
sprintf(buf, "adding %d to %d\n", x, y);
fprintf(stdout, "[INFO] - %s", buf);
fflush(stdout);
return x+y;
}
Manifest:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JNI Test
Bundle-SymbolicName: my.bundle.jni_test
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-NativeCode: natives/libjni_example.so;osname=linux;processor=arm
Export-Package: my.bundle.jni_test
build.properties:
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
natives/libjni_example.so