Loading 3rd party shared libraries from an Android native activity

前端 未结 4 1316
独厮守ぢ
独厮守ぢ 2020-12-14 03:21

I\'ve built the Assimp library as a shared library. I\'ve included it in my Android ndk project and it builds fine but when I load it I get the following error: Unable to lo

4条回答
  •  感情败类
    2020-12-14 04:04

    Using System.loadLibrary is the way to go.

    Android won't automatically load dependent shared libraries for you. So you need to do something like this:

    static {
        System.loadLibrary("assimp");  // dependency .so first
        System.loadLibrary("native-activity"); // dependent .so second
    }
    

    This code usually goes in the class which contains the native Java methods (i.e. methods defined with keyword native, which map through to native code). Because this code is executed in a static block it is executed when the Java classloader loads the class -- i.e. before any code in the class actually gets executed.

    You shouldn't have to add any reference to assimp to LOCAL_LDLIBS because you're already referencing assimp via the LOCAL_SHARED_LIBRARIES declaration.

    This question may be relevant.

提交回复
热议问题