import java.lang.reflect.Field;

import java.util.Enumeration;

import dalvik.system.DexFile;

import dalvik.system.PathClassLoader;

public class Scanner {

private static Field dexField;

static {

try {

dexField = PathClassLoader.class.getDeclaredField("mDexs");

dexField.setAccessible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

public static void scan() {

try {

PathClassLoader classLoader = (PathClassLoader) Thread.currentThread().getContextClassLoader();

DexFile[] dexs = (DexFile[]) dexField.get(classLoader);

for (DexFile dex : dexs) {

Enumeration entries = dex.entries();

while (entries.hasMoreElements()) {

String entry = entries.nextElement();

Class> entryClass = dex.loadClass(entry, classLoader);

if (entryClass != null) {

IBizAnno annotation = entryClass.getAnnotation(IBizAnno.class);

if (annotation != null) {

System.out.println("name=" + annotation.name() + "; class=" + entryClass.getName());

}

}

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐