“Unsatisfied native code filter” when exporting OSGi bundle containing native Android lib

风格不统一 提交于 2020-01-25 03:34:24

问题


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

回答1:


It seems like the target platform defined under 'Window -> Preferences -> Plug-in Development - Target Platform' prevented the export to succeed.

I added a new entry copying the settings from my current target platform (chose option 'Current Target'). There, I changed under 'Environment' the 'Architecture' value to 'arm'. As 'arm' was not an option provided by the drop-down list, I typed it manually into the text field.

That's it. When using this target configuration, everything works fine now. The bundle is exported successfully and I can use it on my Android device.



来源:https://stackoverflow.com/questions/17240627/unsatisfied-native-code-filter-when-exporting-osgi-bundle-containing-native-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!