问题
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:
- 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?
- 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? - May I also share the .so files on the android device across different apps?
回答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):
Run your app from AS
Run adb shell in su mode:
adb shell su ls -als /data/app
- 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.
- 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