我在我的android应用程序中使用资产或sdcard中的外部jar。为了做到这一点,我使用了DexClassLoader。
DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(),
null,
getClassLoader());要加载类,请执行以下操作:
Class myNewClass = cl.loadClass("com.example.dex.lib.LibraryProvider");它真的很好用,但是现在我想在我的DexClassLoader中获得所有类名的列表,我发现this可以在java中工作,但是在android中没有这样的东西。
问题是如何从DexClassLoader获取所有类名的列表
发布于 2012-08-30 20:17:39
要列出包含classes.dex文件的.jar文件中的所有类,请使用DexFile,而不是DexClassLoader,例如:
String path = "/path/to/your/library.jar"
try {
DexFile dx = DexFile.loadDex(path, File.createTempFile("opt", "dex",
getCacheDir()).getPath(), 0);
// Print all classes in the DexFile
for(Enumeration<String> classNames = dx.entries(); classNames.hasMoreElements();) {
String className = classNames.nextElement();
System.out.println("class: " + className);
}
} catch (IOException e) {
Log.w(TAG, "Error opening " + path, e);
}https://stackoverflow.com/questions/12195642
复制相似问题