@@ -1677,10 +1677,13 @@ pbxProject.prototype.removeTargetsByProductType = function(targetProductType) {
1677
1677
1678
1678
pbxProject . prototype . removeTarget = function ( target , targetKey ) {
1679
1679
let files = [ ] ;
1680
+ var pbxBuildFileSection = this . pbxBuildFileSection ( ) ;
1681
+ var fileReferenceSection = this . pbxFileReferenceSection ( ) ;
1680
1682
1681
1683
// iterate all buildPhases and collect all files that should be removed
1682
1684
// remove the phase from the appropriate section
1683
1685
var buildPhases = target [ "buildPhases" ] ;
1686
+
1684
1687
for ( let i = 0 ; i < buildPhases . length ; i ++ ) {
1685
1688
var buildPhase = buildPhases [ i ] ;
1686
1689
var sectionUuid = buildPhase . value ;
@@ -1693,7 +1696,26 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
1693
1696
files = files . concat ( section [ sectionUuid ] . files ) ;
1694
1697
} else if ( buildPhase . comment === buildPhaseNameForIsa ( "PBXFrameworksBuildPhase" ) ) {
1695
1698
section = this . hash . project . objects [ "PBXFrameworksBuildPhase" ] ;
1696
- files = files . concat ( section [ sectionUuid ] . files ) ;
1699
+ var frameworkFiles = section [ sectionUuid ] . files ;
1700
+ for ( let q = 0 ; q < frameworkFiles . length ; q ++ ) {
1701
+ var currentBuildFileUuid = frameworkFiles [ q ] . value ;
1702
+ var fileRef = pbxBuildFileSection [ currentBuildFileUuid ] . fileRef ;
1703
+ var stillReferenced = false ;
1704
+ for ( var buildFileUuid in nonComments ( pbxBuildFileSection ) ) {
1705
+ if ( pbxBuildFileSection [ buildFileUuid ] . fileRef === fileRef && buildFileUuid !== currentBuildFileUuid ) {
1706
+ stillReferenced = true ;
1707
+ }
1708
+ }
1709
+
1710
+ if ( ! stillReferenced ) {
1711
+ var frameworkFileRef = fileReferenceSection [ fileRef ] ;
1712
+ var fileToRemove = new pbxFile ( unquote ( frameworkFileRef . path ) , { basename : frameworkFileRef . name } ) ;
1713
+ fileToRemove . fileRef = fileRef ;
1714
+ this . removeFromFrameworksPbxGroup ( fileToRemove ) ;
1715
+ removeItemAndCommentFromSectionByUuid ( fileReferenceSection , fileRef ) ;
1716
+ }
1717
+ }
1718
+ files = files . concat ( frameworkFiles ) ;
1697
1719
}
1698
1720
1699
1721
removeItemAndCommentFromSectionByUuid ( section , sectionUuid ) ;
@@ -1734,12 +1756,10 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
1734
1756
var productUuid = "" ;
1735
1757
1736
1758
var productReferenceUuid = target . productReference ;
1737
- var pbxBuildFileSection = this . pbxBuildFileSection ( ) ;
1738
- var pbxBuildFileSectionNoComments = nonComments ( pbxBuildFileSection ) ;
1739
1759
1740
1760
// the productReference is the uuid from the PBXFileReference Section, but we need the one in PBXBuildFile section
1741
1761
// check the fileRef of all records until we find the product
1742
- for ( var uuid in pbxBuildFileSectionNoComments ) {
1762
+ for ( var uuid in nonComments ( pbxBuildFileSection ) ) {
1743
1763
if ( this . pbxBuildFileSection ( ) [ uuid ] . fileRef == productReferenceUuid ) {
1744
1764
productUuid = uuid ;
1745
1765
}
@@ -1787,7 +1807,6 @@ pbxProject.prototype.removeTarget = function(target, targetKey) {
1787
1807
1788
1808
1789
1809
//remove the product from the Products PBXGroup
1790
- var fileReferenceSection = this . pbxFileReferenceSection ( ) ;
1791
1810
var productReference = fileReferenceSection [ productReferenceUuid ] ;
1792
1811
var productFile = new pbxFile ( productReference . path ) ;
1793
1812
productFile . fileRef = productReferenceUuid ;
0 commit comments