Android remote code loading

后端 未结 3 993
孤街浪徒
孤街浪徒 2020-12-07 11:08

I am developing a library for Android that requires frequent updates from a central server. I was thinking how nice it would be if my library could update itself -- or if I

3条回答
  •  难免孤独
    2020-12-07 11:25

    DexClassLoader is the right answer. Applications should never use DexFile directly (it's meant to be used by class loaders).

    You could use external storage (/sdcard), or the app's private data area, for the dexOutputDir parameter. External storage is usually larger, but if the card is ejected your app will be killed, and due to the lack of file permission enforcement it's easy for a third party to replace your code. This can allow malicious apps to cause your app to perform arbitrary actions. (If you want to do it anyway, get the path via Environment.getExternalStorageDirectory(); requires the WRITE_EXTERNAL_STORAGE permission.)

    The app-private data area (get the path from Context.getFilesDir()) is more secure, and also has the advantage of being cleaned up automatically if the app is uninstalled. This is the recommended approach.

提交回复
热议问题