我的 android 应用程序所需的 c++ .so 库放在哪里

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

我制作了一个基于 ndk 的 android 应用程序,当我 运行 通过单击 Android Studio 中的 运行 按钮时,我发现该应用程序已安装, 运行ning 在我连接的 android 设备上。但它抱怨它无法加载一些 .so 文件,如 libc++_shared.solibomp.so,我做了一些研究,并在我的 app\src\main 文件夹中创建了一个 jniLibs,并复制了这些文件将两个 .so 文件放入其中,现在一切正常。

但是,我仍然不清楚到底发生了什么:

  1. 当我点击 运行 按钮时,应用程序在设备上 installed/saved 的位置,.so 文件是否复制到同一位置?
  2. 我怀疑将 .so 文件复制到 jniLibs 是否是一个好习惯,这样的 .so 文件可以被许多应用程序共享,如果每个应用程序都有自己的副本,更新它们就会变得困难。有没有办法将它们存储在一个公共位置以供应用程序共享?
  3. 我还可以在 android 设备上跨不同的应用程序共享 .so 文件吗?
  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?

应用程序保存在 /data/app/your.app.name-cert-hash== 上,.so 库保存在同一位置,例如/data/app/your.app.name-cert-hash==/lib/x86(如果android:extractNativeLibs="true" in AndroidManifest.xml/application,否则库直接压缩为.apk)。

要发现 Android 文件系统,您可以使用 ADB(以及模拟器):

  1. 运行 你的应用来自 AS

  2. 运行 adb shell 在 su 模式下:

    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?

由于 Android 安全措施,这是不可能的。

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

没有