Java Reflections doesn't work with Android instant run -
i'm writing code uses java reflections on it. i'm scanning package class using method:
/** * called list of classes included in current project * * @param packagename 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); (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 upgraded gradle
version 2.1.0
trying out instant run feature, noticed app package returns empty string[]
method , method returns classes inside package name com.android.tools.fd.*
why can't see classes in app package?!
if see "packagecodepath" value after instant run deploying , simple install, can see values differ.
for example, in project saw this:
instant run: /data/app/com.app-1/base.apk not instant run: /data/app/com.app-1.apk
after watched mnamelist in dexfile instance , surprised differs in 2 modes! in instant run mode watched 30 classes, instead of not instant run mode.
i don't know deep details of process, think caused ideology of instant run replacing modified classes.
maybe answer useful you.