in android/src/org/jetbrains/android/facet/AndroidRootUtil.java [134:208]
private static void fillExternalLibrariesAndModules(@NotNull final Module module,
@NotNull final Set<VirtualFile> outputDirs,
@NotNull final Set<Module> visited,
@Nullable final Set<VirtualFile> libraries,
final boolean exportedLibrariesOnly,
final boolean recursive) {
if (!visited.add(module)) {
return;
}
ApplicationManager.getApplication().runReadAction(() -> {
ModuleRootManager manager = ModuleRootManager.getInstance(module);
for (OrderEntry entry : manager.getOrderEntries()) {
if (!(entry instanceof ExportableOrderEntry) || ((ExportableOrderEntry)entry).getScope() != DependencyScope.COMPILE) {
continue;
}
if (libraries != null && entry instanceof LibraryOrderEntry) {
LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry)entry;
Library library = libraryOrderEntry.getLibrary();
if (library != null && (!exportedLibrariesOnly || libraryOrderEntry.isExported())) {
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
if (!file.exists()) {
continue;
}
if (file.getFileType() instanceof ArchiveFileType) {
if (file.getFileSystem() instanceof JarFileSystem) {
VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
if (localFile != null) {
libraries.add(localFile);
}
}
else {
libraries.add(file);
}
}
else if (file.isDirectory() && !(file.getFileSystem() instanceof JarFileSystem)) {
collectClassFilesAndJars(file, libraries, new HashSet<>());
}
}
}
}
else if (entry instanceof ModuleOrderEntry) {
Module depModule = ((ModuleOrderEntry)entry).getModule();
if (depModule == null) {
continue;
}
AndroidFacet facet = AndroidFacet.getInstance(depModule);
boolean libraryProject = facet != null && facet.getConfiguration().isLibraryProject();
CompilerModuleExtension extension = CompilerModuleExtension.getInstance(depModule);
if (extension != null) {
VirtualFile classDir = extension.getCompilerOutputPath();
if (libraryProject) {
VirtualFile tmpArtifactsDir = CompilerModuleExtension.getInstance(depModule).getCompilerOutputPath();;
if (tmpArtifactsDir != null) {
VirtualFile packedClassesJar = tmpArtifactsDir.findChild(CLASSES_JAR_FILE_NAME);
if (packedClassesJar != null) {
outputDirs.add(packedClassesJar);
}
}
}
// do not support android-app->android-app compile dependencies
else if (facet == null && !outputDirs.contains(classDir) && classDir != null && classDir.exists()) {
outputDirs.add(classDir);
}
}
if (recursive) {
fillExternalLibrariesAndModules(depModule, outputDirs, visited, libraries, !libraryProject || exportedLibrariesOnly, true);
}
}
}
});
}