I'm writing some code that uses java reflections on it. I'm scanning my package for a certain class using this method:
/**
* Called to get list of classes included in the current project
*
* @param packageName the name of application package
* @return array of classes' names
*/
private String[] getClassesOfPackage(String packageName) {
ArrayList<String> classes = new ArrayList<>();
try {
String packageCodePath = getPackageCodePath();
DexFile df = new DexFile(packageCodePath);
for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); ) {
String className = iter.nextElement();
if (className.contains(packageName)) {
classes.add(className);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return classes.toArray(new String[classes.size()]);
}
recently I upgraded my Gradle
version to 2.1.0
for trying out instant run feature, but I noticed that my app package usually returns empty String[]
from this method and this method only returns classes inside a package with name com.android.tools.fd.*
Why can't I see classes in my app package?!