@@ -338,14 +338,19 @@ pbxProject.prototype.addFramework = function(fpath, opt) {
338338 file . fileRef = this . generateUuid ( ) ;
339339 file . target = opt ? opt . target : undefined ;
340340
341- if ( this . hasFile ( file . path ) ) return false ;
342-
343- this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
344- this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
345- this . addToFrameworksPbxGroup ( file ) ; // PBXGroup
341+ var fileReference = this . hasFile ( file . path ) ;
342+ if ( fileReference ) {
343+ var key = this . getFileKey ( file . path ) ;
344+ file . fileRef = key ;
345+ } else {
346+ this . addToPbxFileReferenceSection ( file ) ; // PBXFileReference
347+ this . addToFrameworksPbxGroup ( file ) ; // PBXGroup
348+ }
346349
347350 if ( link ) {
348- this . addToPbxFrameworksBuildPhase ( file ) ; // PBXFrameworksBuildPhase
351+ if ( this . addToPbxFrameworksBuildPhase ( file ) ) { // PBXFrameworksBuildPhase)
352+ this . addToPbxBuildFileSection ( file ) ; // PBXBuildFile
353+ }
349354 }
350355
351356 if ( customFramework ) {
@@ -357,13 +362,13 @@ pbxProject.prototype.addFramework = function(fpath, opt) {
357362
358363 embeddedFile . uuid = this . generateUuid ( ) ;
359364 embeddedFile . fileRef = file . fileRef ;
365+ embeddedFile . target = file . target ;
360366
361- //keeping a separate PBXBuildFile entry for Embed Frameworks
362- this . addToPbxBuildFileSection ( embeddedFile ) ; // PBXBuildFile
363-
364- this . addToPbxEmbedFrameworksBuildPhase ( embeddedFile ) ; // PBXCopyFilesBuildPhase
365-
366- return embeddedFile ;
367+ if ( this . addToPbxEmbedFrameworksBuildPhase ( embeddedFile ) ) { // PBXCopyFilesBuildPhase
368+ //keeping a separate PBXBuildFile entry for Embed Frameworks
369+ this . addToPbxBuildFileSection ( embeddedFile ) ; // PBXBuildFile
370+ return embeddedFile ;
371+ }
367372 }
368373 }
369374
@@ -856,10 +861,25 @@ pbxProject.prototype.removeFromFrameworksPbxGroup = function(file) {
856861 }
857862}
858863
864+ function hasReferenceInPbxBuildFile ( buildFileReferences , fileReference ) {
865+ var buildFileSection = this . pbxBuildFileSection ( ) ;
866+ for ( let buildFileReference of buildFileReferences ) {
867+ if ( buildFileSection [ buildFileReference . value ] && buildFileSection [ buildFileReference . value ] . fileRef === fileReference . fileRef ) {
868+ return true ;
869+ }
870+ }
871+ }
872+
859873pbxProject . prototype . addToPbxEmbedFrameworksBuildPhase = function ( file ) {
860874 var sources = this . pbxEmbedFrameworksBuildPhaseObj ( file . target ) ;
875+
861876 if ( sources ) {
877+ if ( hasReferenceInPbxBuildFile . call ( this , sources . files , file ) ) {
878+ return false ;
879+ }
880+
862881 sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
882+ return true ;
863883 }
864884}
865885
@@ -933,7 +953,15 @@ pbxProject.prototype.removeFromPbxResourcesBuildPhase = function(file) {
933953
934954pbxProject . prototype . addToPbxFrameworksBuildPhase = function ( file ) {
935955 var sources = this . pbxFrameworksBuildPhaseObj ( file . target ) ;
936- sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
956+
957+ if ( sources ) {
958+ if ( hasReferenceInPbxBuildFile . call ( this , sources . files , file ) ) {
959+ return false ;
960+ }
961+
962+ sources . files . push ( pbxBuildPhaseObj ( file ) ) ;
963+ return true ;
964+ }
937965}
938966
939967pbxProject . prototype . removeFromPbxFrameworksBuildPhase = function ( file ) {
@@ -1353,8 +1381,10 @@ pbxProject.prototype.addToFrameworkSearchPaths = function(file) {
13531381 || buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] === INHERITED ) {
13541382 buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] = [ INHERITED ] ;
13551383 }
1356-
1357- buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . push ( searchPathForFile ( file , this ) ) ;
1384+ var searchPath = searchPathForFile ( file , this ) ;
1385+ if ( buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . indexOf ( searchPath ) < 0 ) {
1386+ buildSettings [ 'FRAMEWORK_SEARCH_PATHS' ] . push ( searchPath ) ;
1387+ }
13581388 }
13591389}
13601390
@@ -1565,6 +1595,19 @@ pbxProject.prototype.hasFile = function(filePath) {
15651595 return false ;
15661596}
15671597
1598+ pbxProject . prototype . getFileKey = function ( filePath ) {
1599+ var files = nonComments ( this . pbxFileReferenceSection ( ) ) ,
1600+ file , id ;
1601+ for ( id in files ) {
1602+ file = files [ id ] ;
1603+ if ( file . path == filePath || file . path == ( '"' + filePath + '"' ) ) {
1604+ return id ;
1605+ }
1606+ }
1607+
1608+ return false ;
1609+ }
1610+
15681611pbxProject . prototype . addTarget = function ( name , type , subfolder ) {
15691612
15701613 // Setup uuid and name of new target
0 commit comments