关于/data/data/目录的一些重要结论

1. /data/data/com.your.packagename/files   
   /data/data/com.your.packagename/databases
   这两个目录,程序是可以操作的。可以在其中创建目录,向其中拷贝文件、删除文件等。
   比较典型的用法是程序内置的数据库,初次使用时将其从assert拷贝到databases目录下。
   另外,context.getFileDir返回的是/data/data/com.your.packagename/files目录,context.openFile()也是打开这个目录下的文件。
2. /data/data/com.your.packagename/lib
   这个目录是程序不能操作的,即意味着“不能在程序运行时,向该目录拷贝so文件,以便调用System.loadLibrary()开加载该so”。
   可能许多程序有类似的需要,但是拷贝到lib目录是不可行的。
3. System.load(path) 不能加载sdcard中的so,具体参见:
---- start [不能加载sdcard中的so] ------ // http://stackoverflow.com/questions/11582717/android-can-write-to-lib-dir
You can write to any non-reserved location within your your application's private storage area, 
and you can load a native library from any file on the device for which you have read and execute permission, using System.load() with the full pathname,
rather than System.loadLibrary() with the short library name.


The external storage (sdcard) is mounted with a non-executable flag, //[Note: important]
but a file in your private storage directory would be a workable solution. 
Just be sure to make it only writable by your application, so that something else can't change it behind your back 
(it is because you cannot protect external storage files from such modification that the external storage is non-executable)
------ end ------


------ start [不能加载sdcard中的so]------ // http://stackoverflow.com/questions/6291087/android-load-library-error-failed-to-map-segment
You cannot load native libraries or execute binaries located on the SDCard. It is mounted noexec. //[Note: important]
You need to copy the library to the internal storage before you load it, that is, in a subdirectory of dataDir, eg:


PackageManager pm = context.getPackageManager();
String dataDir = pm.getApplicationInfo(context.getPackageName(), 0).dataDir;
------ end ------


------ start [不能加载sdcard中的so] ------ // http://stackoverflow.com/questions/2826412/how-to-load-jni-from-sd-card-on-android-2-1
Android's dynamic loader cannot load executable code from the sdcard's filesystem,
because it is marked non-executable and you cannot map executable memory pages from non-executable storage. 
(In theory you could manually copy the contents into executable anonymous mapped pages, but that's ugly.
Versions of android supporting apps on SD mount an executable file systems contained within a file on the sdcard, but a third party app can't write those)


But what you can do is write a library to a writable location in internal storage - not the lib directory to which you don't have write access, 
but another one found from Context.getDir() or Context.getFilesDir() and then load it using the full path and .so file name using System.load() instead of System.loadLibrary().
------ end ------


------ start [load多个so库,期间存在依赖关系]------ // http://stackoverflow.com/questions/3631201/android-failure-on-loading-library


应用安装后,想要“加载未内置入apk包”中的so,需要先将该so放入/data/data/your.package.name/files(或者databases)目录,然后调用System.load(path)方法来加载so. 


4. System.loadLibrary过程详见,可以参见: http://my.oschina.net/wolfcs/blog/129696


5. 非root下,操作/data/data目录下的数据:// http://stackoverflow.com/questions/13006315/how-to-access-data-data-folder-in-android-device
------
If the application is debuggable you can use the run-as command in adb shell
adb shell
run-as com.your.packagename 
cp /data/data/com.your.pacakagename/
------ 
You can use Android's backup function.
adb backup -noapk com.your.packagename

你可能感兴趣的:(Android应用)