Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best place to put downloaded native library in Android?

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?

like image 717
frankish Avatar asked Nov 02 '22 11:11

frankish


1 Answers

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.

like image 150
A. Rager Avatar answered Nov 15 '22 03:11

A. Rager