我在我的 Android 应用程序中使用来自 asset 或 sdcard 的外部 jar。为此,我使用 DexClassLoader。
DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(),
null,
getClassLoader());
加载一个类:
Class myNewClass = cl.loadClass("com.example.dex.lib.LibraryProvider");
它工作得非常好,但现在我想获取 DexClassLoader 中所有类名称的列表
我发现this http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/Instrumentation.html#getInitiatedClasses%28java.lang.ClassLoader%29在java中工作,但在android中没有这样的东西。
问题是我如何从 DexClassLoader 获取所有类名称的列表
列出包含以下内容的 .jar 文件中的所有类classes.dex
你使用的文件DexFile
, not 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)