How can i find all classes inside a package on Android? I use PathClassLoader, but it always returns an empty enumeration?
Additional info
Tried the suggested Reflections approach. Couple of important points about reflections library. The library available through maven central is not compatible with Android and gives dex errors. I had to include source and compile dom4j, java-assist.
The problem with reflections, and my original solution is that PathClassLoader in android returns an empty enumeration for package.
The issue with approach is that getResource in Android is always returning empty enumeration.
final String resourceName = aClass.getName().replace(".", "/") + ".class";
for (ClassLoader classLoader : loaders) {
try {
final URL url = classLoader.getResource(resourceName);
if (url != null) {
final String normalizedUrl = url.toExternalForm().substring(0, url.toExternalForm().lastIndexOf(aClass.getPackage().getName().replace(".", "/")));
return new URL(normalizedUrl);
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
}