3

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?!

mnagy
  • 1,085
  • 1
  • 17
  • 36

1 Answers1

0

If you will see a "packageCodePath" value after Instant Run deploying and simple install, you can see that values a differ.

For example, in my project I saw something like this:

Instant run: /data/app/com.app-1/base.apk
Not instant run: /data/app/com.app-1.apk

After that I watched for mNameList in DexFile instance and I was surprised that it differs in those 2 modes! In instant run mode I watched only about 30 classes, instead of not instant run mode.

I don't know deep details of that process, but I think it caused by ideology of Instant Run with replacing modified classes.

Maybe my answer was useful for you.

b00blik
  • 31
  • 4