1.用于动态加载的dex可以放在sdcard中进行加载,但是为了安全起见还是觉得放在asset中,
加载之前把dex复制到app的data空间中更好。
String copyDex(String dexName) { AssetManager as = getAssets(); String path = getFilesDir() + File.separator + dexName; Log.i(TAG, path); try { FileOutputStream out = new FileOutputStream(path); InputStream is = as.open(dexName); int count = is.available(); while (count > 0) { byte[] buffer = new byte[count > 1024 ? 1024 : count]; int len = is.read(buffer); out.write(buffer); count -= len; } out.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return ""; } return path; }
2.使用前面生成的dex文件构造DexClassLoader对象生成优化后的dex文件。
public void loadDex() { String path = copyDex("
android APK加固篇-2.动态加载dex及dex的方法的调用
最新推荐文章于 2025-03-30 11:28:30 发布