private void findClassesInApk(String apkPath,String packageName,Set<String> classNames,Set<String> subpackageNames) throws IOException {
  DexFile dexFile=null;
  try {
    dexFile=new DexFile(apkPath);
    Enumeration<String> apkClassNames=dexFile.entries();
    while (apkClassNames.hasMoreElements()) {
      String className=apkClassNames.nextElement();
      if (className.startsWith(packageName)) {
        String subPackageName=packageName;
        int lastPackageSeparator=className.lastIndexOf('.');
        if (lastPackageSeparator > 0) {
          subPackageName=className.substring(0,lastPackageSeparator);
        }
        if (subPackageName.length() > packageName.length()) {
          subpackageNames.add(subPackageName);
        }
 else         if (isToplevelClass(className)) {
          classNames.add(className);
        }
      }
    }
  }
 catch (  IOException e) {
    if (false) {
      Log.w("ClassPathPackageInfoSource","Error finding classes at apk path: " + apkPath,e);
    }
  }
 finally {
    if (dexFile != null) {
    }
  }
}

private void findClassesInApk ( String apkPath , String packageName , Set < String > classNames , Set < String > subpackageNames ) throws IOException { DexFile dexFile = null ; try { dexFile = new DexFile ( apkPath ) ; Enumeration < String > apkClassNames = dexFile . entries ( ) ; while ( apkClassNames . hasMoreElements ( ) ) { String className = apkClassNames . nextElement ( ) ; if ( className . startsWith ( packageName ) ) { String subPackageName = packageName ; int lastPackageSeparator = className . lastIndexOf ( '.' ) ; if ( lastPackageSeparator > 0 ) { subPackageName = className . substring ( 0 , lastPackageSeparator ) ; } if ( subPackageName . length ( ) > packageName . length ( ) ) { subpackageNames . add ( subPackageName ) ; } else if ( isToplevelClass ( className ) ) { classNames . add ( className ) ; } } } } catch ( IOException e ) { if ( false ) { Log . w ( "ClassPathPackageInfoSource" , "Error finding classes at apk path: " + apkPath , e ) ; } } finally { if ( dexFile != null ) { } } }
finds all classes and sub packages that are below the packagename and add them to the respective sets . searches the package in a single apk file .
