diff --git a/plugins/android/src/org/jetbrains/android/compiler/AndroidAptCompiler.java b/plugins/android/src/org/jetbrains/android/compiler/AndroidAptCompiler.java index 60d5385b24eb..28e14d13aa05 100644 --- a/plugins/android/src/org/jetbrains/android/compiler/AndroidAptCompiler.java +++ b/plugins/android/src/org/jetbrains/android/compiler/AndroidAptCompiler.java @@ -211,7 +211,7 @@ public class AndroidAptCompiler implements SourceGeneratingCompiler { AndroidFacet facet = AndroidFacet.getInstance(module); if (facet != null) { AndroidFacetConfiguration configuration = facet.getConfiguration(); - if (!isToCompileModule(module, configuration)) { + if (!isToCompileModule(module, configuration) || hasBadCircularDependencies(facet)) { continue; } @@ -261,6 +261,40 @@ public class AndroidAptCompiler implements SourceGeneratingCompiler { return items.toArray(new GenerationItem[items.size()]); } + + // see IDEA-79737 for details + private static boolean hasBadCircularDependencies(@NotNull AndroidFacet facet) { + final List dependencies = AndroidSdkUtils.getAllAndroidDependencies(facet.getModule(), true); + + final Manifest manifest = facet.getManifest(); + if (manifest == null) { + return false; + } + + final String aPackage = manifest.getPackage().getValue(); + if (aPackage == null || aPackage.length() == 0) { + return false; + } + + for (AndroidFacet depFacet : dependencies) { + final Manifest depManifest = depFacet.getManifest(); + + if (depManifest != null) { + if (!aPackage.equals(depManifest.getPackage().getValue())) { + continue; + } + } + final List depDependencies = AndroidSdkUtils.getAllAndroidDependencies(depFacet.getModule(), true); + + if (depDependencies.contains(facet) && + dependencies.contains(depFacet) && + depFacet.getModule().getName().compareTo(facet.getModule().getName()) < 0) { + return true; + } + } + return false; + } + @NotNull private static String[] getLibPackages(@NotNull Module module, @NotNull String packageName) { final Set packageSet = new HashSet();