所有类的安卓dexclassloader获取列表 [英] android dexclassloader get list of all classes
问题描述
我使用的资产或SD卡外部JAR在我的Android应用程序。要做到这一点,我使用DexClassLoader。
I am using external jar from assets or sdcard in my android application. To do that I am using DexClassLoader.
DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(),
null,
getClassLoader());
要加载类:
Class myNewClass = cl.loadClass("com.example.dex.lib.LibraryProvider");
它的作品真的不错,但现在我想在我的DexClassLoader的所有类名称列表 我发现<一href="http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/Instrumentation.html#getInitiatedClasses%28java.lang.ClassLoader%29">this在java中工作,但没有这样的事情的机器人。
it works really nice but now I want to get list of all classes names in my DexClassLoader I found this to work in java but there is no such thing in android.
问题是如何我能得到的所有类的名称列表,DexClassLoader
Question is how i can get list of all classes names from DexClassLoader
推荐答案
要列出一个.jar文件包含 classes.dex
文件中使用<$ C所有课程$ C> DexFile ,不是 DexClassLoader
,例如:像这样的:
To list all classes in a .jar file containing a classes.dex
file you use DexFile
, not DexClassLoader
, e.g. like this:
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);
}
这篇关于所有类的安卓dexclassloader获取列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!