Where to put c++ .so library needed for my android application

吃可爱长大的小学妹 提交于 2021-02-08 10:37:25

问题


I made an ndk based android app, and when I run it by clicking the run button in Android Studio, I found the app been installed, and running on my connected android device. But it complains that it could not load some .so files like libc++_shared.so and libomp.so, I did some research, and created a jniLibs in my app\src\main folder, and copied those two .so files into that, now everything works fine.

However, it is still unclear to me what happened exactly:

  1. when I click the run button, where the app is installed/saved on the device, and is the .so files copied to the same location?
  2. I suspect if it is a good practice to copy the .so files to the jniLibs, such .so files could be shared by many apps, updating them become difficult if every app has its own copy. Is there are way to store them in a common place to be shared by apps?
  3. May I also share the .so files on the android device across different apps?

回答1:


  1. when I click the run button, where the app is installed/saved on the device, and is the .so files copied to the same location?

App is saved on /data/app/your.app.name-cert-hash== and .so libraries are stored in the same location, e.g. /data/app/your.app.name-cert-hash==/lib/x86 (if android:extractNativeLibs="true" in AndroidManifest.xml/application, otherwise libraries are directly compressed to .apk).

For discovering Android file system you can use ADB (with emulator as well):

  1. Run your app from AS

  2. Run adb shell in su mode:

    adb shell
    su
    ls -als /data/app
    
  1. I suspect if it is a good practice to copy the .so files to the jniLibs, such .so files could be shared by many apps, updating them become difficult if every app has its own copy. Is there are way to store them in a common place to be shared by apps?

It is not possible due to Android security approach.

  1. May I also share the .so files on the android device across different apps?

No.



来源:https://stackoverflow.com/questions/63219377/where-to-put-c-so-library-needed-for-my-android-application

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