DexClassLoader on Android Honeycomb

怎甘沉沦 提交于 2019-12-05 02:53:55

I know this is an old post, but I recently needed an answer to this without upgrading to Android 3.1, so I thought I would share my solution.

I used the "DexFile" class instead of the "DexClassLoader", since it allowed me to pass the output file, thus getting around the issue with the output directory being ignored.

Here's my code:

final File dexClasses = new File("/sdcard/dexcontainer.zip");
DexFile dexFile = DexFile.loadDex(dexClasses.getAbsolutePath(), getFilesDir().getAbsolutePath() + "/outputdexcontainer.dex", 0);

Enumeration<String> classFileNames = dexFile.entries();
while (classFileNames.hasMoreElements())
{
  String className = classFileNames.nextElement();
  dexFile.loadClass(className, classLoader);
}

Hope this helps someone.

Looking at the change history, this should be fixed in Android 3.1.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!