use of com.android.tools.idea.res.FileResourceRepository in project android by JetBrains.
the class ModuleClassLoader method getExternalJars.
@Override
protected List<URL> getExternalJars() {
final Module module = myModuleReference.get();
if (module == null) {
return Collections.emptyList();
}
final List<URL> result = new ArrayList<>();
if (ThemeEditorProvider.THEME_EDITOR_ENABLE) {
URL customWidgetsUrl = ThemeEditorUtils.getCustomWidgetsJarUrl();
if (customWidgetsUrl != null) {
result.add(customWidgetsUrl);
}
}
List<VirtualFile> externalLibraries;
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null && facet.requiresAndroidModel() && facet.getAndroidModel() != null) {
AndroidModel androidModel = facet.getAndroidModel();
externalLibraries = androidModel.getClassJarProvider().getModuleExternalLibraries(module);
} else {
externalLibraries = AndroidRootUtil.getExternalLibraries(module);
}
for (VirtualFile libFile : externalLibraries) {
if (EXT_JAR.equals(libFile.getExtension())) {
final File file = new File(libFile.getPath());
if (file.exists()) {
try {
result.add(SdkUtils.fileToUrl(file));
File aarDir = file.getParentFile();
if (aarDir != null && (aarDir.getPath().endsWith(DOT_AAR) || aarDir.getPath().contains(EXPLODED_AAR))) {
if (aarDir.getPath().contains(EXPLODED_AAR)) {
if (aarDir.getPath().endsWith(LIBS_FOLDER)) {
// Some libraries recently started packaging jars inside a sub libs folder inside jars
aarDir = aarDir.getParentFile();
}
// Gradle plugin version 1.2.x and later has classes in aar-dir/jars/
if (aarDir.getPath().endsWith(FD_JARS)) {
aarDir = aarDir.getParentFile();
}
}
AppResourceRepository appResources = AppResourceRepository.getAppResources(module, true);
if (appResources != null) {
ResourceClassRegistry.get(module.getProject()).addAarLibrary(appResources, aarDir);
}
} else if (aarDir != null) {
// Build cache? We need to compute the package name in a slightly different way
File parentFile = aarDir.getParentFile();
if (parentFile != null) {
File manifest = new File(parentFile, ANDROID_MANIFEST_XML);
if (manifest.exists()) {
AppResourceRepository appResources = AppResourceRepository.getAppResources(module, true);
if (appResources != null) {
FileResourceRepository repository = appResources.findRepositoryFor(parentFile);
if (repository != null) {
ResourceClassRegistry registry = ResourceClassRegistry.get(module.getProject());
registry.addLibrary(appResources, registry.getAarPackage(parentFile));
}
}
}
}
}
} catch (MalformedURLException e) {
LOG.error(e);
}
}
}
}
return result;
}
Aggregations