androidandroid-ndkshared-librariesndk-build

Is there a way to don't include .so file if I use created ndk lib?


I created Android lib that use NDK ArCore

https://developers.google.com/ar/develop/c/enable-arcore

Then I built a lib and got .aar file. Then I created new sample project and included this .aar file like a module (import .JAR/.AAR package) and linked it like dependency, so all works fine.

Issue is - when I try to call method that use ArCore I am getting such error

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.ar, PID: 7822
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libarcore_sdk_c.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
        at java.lang.System.loadLibrary(System.java:1669)
        at com..libtetplayer.JniInterface.<clinit>(JniInterface.java:32)
        at com..libtetplayer.JniInterface.createNativeApplication(Native Method)
        at com.example.ar.MainActivity.onCreate(MainActivity.kt:20)
        at android.app.Activity.performCreate(Activity.java:7326)
        at android.app.Activity.performCreate(Activity.java:7317)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3235)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1926)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6990)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

In order to fix it: After I build my lib there are some autogenerated files under build dir, there I found arcore-native dir and there four dirs

enter image description here

I just moved this source to my sample project under the main dir and now it is completely works

Question is - is there is a way to don't include this dirs with .so files in project when implementing the lib? Maybe I need to include them directly to lib somehow?

P.S. Because it is a little bit hard everytime ask user that want to implement my lib also include a few dirs with .so files...


Solution

  • You can put the .so files from arcore-native in your .aar file and they will be delivered with your lib.