M K*_*icz 8 android classloader
我在我的android应用程序中使用来自资产或sdcard的外部jar.为此,我使用DexClassLoader.
DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(),
null,
getClassLoader());
Run Code Online (Sandbox Code Playgroud)
加载一个类:
Class myNewClass = cl.loadClass("com.example.dex.lib.LibraryProvider");
Run Code Online (Sandbox Code Playgroud)
它工作得很好但现在我想得到我的DexClassLoader中的所有类名列表我发现这在java中工作但是在android中没有这样的东西.
问题是如何从DexClassLoader获取所有类名的列表
Jen*_*ens 13
列出包含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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5700 次 |
| 最近记录: |