I want my Android application to download a .so file (native library compiled by me) according to the device's features at runtime, so the size of the apk will be small as I won't be filling the apk with many different versions of the native library.
I couldn't figure out the right place to download this library. Where is the preferred and recommended directory for this So I can use System.loadLibrary function to load it quickly and safely?
If you unzip an apk, you'll see that there's a folder lib
in the root directory. This directory also exists in your application's directory /data/data/package.name/lib
as a symlink to /data/app-lib/package.name
. If you really want to download native libraries at runtime, one of those is where you would have to put them.
Since the applications can get write permissions to their own data directory, you should be able to actually download a file, there. ContextWrapper.getFilesDir()
will return the path /data/data/package.name
so that you don't hardcode it.
Be careful with this - doing native code updates on your own could be more problems than its worth. If you're really trying to be safe, consider the implications of being able to download and run arbitrary native code in your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With