@@ -40,6 +40,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
40
40
private $devicesService : Mobile . IDevicesService ,
41
41
private $mobileHelper : Mobile . IMobileHelper ,
42
42
private $pluginVariablesService : IPluginVariablesService ,
43
+ private $staticConfig : IStaticConfig ,
44
+ private $sysInfo : ISysInfo ,
43
45
private $xcodeSelectService : IXcodeSelectService ) {
44
46
super ( $fs , $projectData , $projectDataService ) ;
45
47
}
@@ -146,7 +148,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
146
148
this . replaceFileName ( "-Prefix.pch" , projectRootFilePath ) . wait ( ) ;
147
149
this . replaceFileName ( IOSProjectService . XCODE_PROJECT_EXT_NAME , this . platformData . projectRoot ) . wait ( ) ;
148
150
149
- let pbxprojFilePath = path . join ( this . platformData . projectRoot , this . $projectData . projectName + IOSProjectService . XCODE_PROJECT_EXT_NAME , "project.pbxproj" ) ;
151
+ let pbxprojFilePath = this . pbxProjPath ;
150
152
this . replaceFileContent ( pbxprojFilePath ) . wait ( ) ;
151
153
} ) . future < void > ( ) ( ) ;
152
154
}
@@ -355,7 +357,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
355
357
let isUpdateConfirmed = this . $prompter . confirm ( `We need to override xcodeproj file. The old one will be saved at ${ this . $options . profileDir } . Are you sure?` , ( ) => true ) . wait ( ) ;
356
358
if ( isUpdateConfirmed ) {
357
359
// Copy old file to options["profile-dir"]
358
- let sourceDir = path . join ( this . platformData . projectRoot , ` ${ this . $projectData . projectName } .xcodeproj` ) ;
360
+ let sourceDir = this . xcodeprojPath ;
359
361
let destinationDir = path . join ( this . $options . profileDir , "xcodeproj" ) ;
360
362
this . $fs . deleteDirectory ( destinationDir ) . wait ( ) ;
361
363
shell . cp ( "-R" , path . join ( sourceDir , "*" ) , destinationDir ) ;
@@ -367,7 +369,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
367
369
shell . cp ( "-R" , path . join ( cachedPackagePath , "*" ) , sourceDir ) ;
368
370
this . $logger . info ( `Copied from ${ cachedPackagePath } at ${ this . platformData . projectRoot } .` ) ;
369
371
370
- let pbxprojFilePath = path . join ( this . platformData . projectRoot , this . $projectData . projectName + IOSProjectService . XCODE_PROJECT_EXT_NAME , "project.pbxproj" ) ;
372
+ let pbxprojFilePath = this . pbxProjPath ;
371
373
this . replaceFileContent ( pbxprojFilePath ) . wait ( ) ;
372
374
}
373
375
@@ -512,6 +514,14 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
512
514
return ( < IPluginsService > this . $injector . resolve ( "pluginsService" ) ) . getAllInstalledPlugins ( ) ;
513
515
}
514
516
517
+ private get xcodeprojPath ( ) : string {
518
+ return path . join ( this . platformData . projectRoot , this . $projectData . projectName + IOSProjectService . XCODE_PROJECT_EXT_NAME ) ;
519
+ }
520
+
521
+ private get cocoaPodsXcodeprojPath ( ) : string {
522
+ return path . join ( this . platformData . projectRoot , "Pods" , "Pods" + IOSProjectService . XCODE_PROJECT_EXT_NAME ) ;
523
+ }
524
+
515
525
private get projectPodFilePath ( ) : string {
516
526
return path . join ( this . platformData . projectRoot , "Podfile" ) ;
517
527
}
@@ -539,7 +549,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
539
549
}
540
550
541
551
private get pbxProjPath ( ) : string {
542
- return path . join ( this . platformData . projectRoot , this . $projectData . projectName + ".xcodeproj" , "project.pbxproj" ) ;
552
+ return path . join ( this . xcodeprojPath , "project.pbxproj" ) ;
543
553
}
544
554
545
555
private createPbxProj ( ) : any {
@@ -585,8 +595,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
585
595
this . $logger . warn ( `Podfile contains more than one post_install sections. You need to open ${ this . projectPodFilePath } file and manually resolve this issue.` ) ;
586
596
}
587
597
588
- let pbxprojFilePath = path . join ( this . platformData . projectRoot , this . $projectData . projectName + IOSProjectService . XCODE_PROJECT_EXT_NAME , "xcuserdata" ) ;
589
- if ( ! this . $fs . exists ( pbxprojFilePath ) . wait ( ) ) {
598
+ let xcuserDataPath = path . join ( this . xcodeprojPath , "xcuserdata" ) ;
599
+ if ( ! this . $fs . exists ( xcuserDataPath ) . wait ( ) ) {
590
600
this . $logger . info ( "Creating project scheme..." ) ;
591
601
let createSchemeRubyScript = `ruby -e "require 'xcodeproj'; xcproj = Xcodeproj::Project.open('${ this . $projectData . projectName } .xcodeproj'); xcproj.recreate_user_schemes; xcproj.save"` ;
592
602
this . $childProcess . exec ( createSchemeRubyScript , { cwd : this . platformData . projectRoot } ) . wait ( ) ;
@@ -664,6 +674,24 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
664
674
this . $errors . failWithoutHelp ( "CocoaPods or ruby gem 'xcodeproj' is not installed. Run `sudo gem install cocoapods` and try again." ) ;
665
675
}
666
676
677
+ let cocoapodsVer = this . $sysInfo . getSysInfo ( this . $staticConfig . pathToPackageJson ) . wait ( ) . cocoapodVer ,
678
+ xcodeVersion = this . $xcodeSelectService . getXcodeVersion ( ) . wait ( ) ;
679
+
680
+ xcodeVersion . patch = xcodeVersion . patch || "0" ;
681
+ let shouldUseXcproj = semver . lt ( cocoapodsVer , "1.0.0" ) && ~ helpers . versionCompare ( xcodeVersion , "7.3.0" ) ;
682
+
683
+ // CocoaPods with version lower than 1.0.0 don't support Xcode 7.3 yet
684
+ // https://github.com/CocoaPods/CocoaPods/issues/2530#issuecomment-210470123
685
+ // as a result of this all .pbxprojects touched by CocoaPods get converted to XML plist format
686
+ if ( shouldUseXcproj ) {
687
+ // if that's the case we can use xcproj gem to convert them back to ASCII plist format
688
+ try {
689
+ this . $childProcess . exec ( "xcproj --version" ) . wait ( ) ;
690
+ } catch ( e ) {
691
+ this . $errors . failWithoutHelp ( `You are using CocoaPods version ${ cocoapodsVer } which does not support Xcode ${ xcodeVersion . major } .${ xcodeVersion . minor } yet. In order for the NativeScript CLI to be able to work correctly with this setup you need to install xcproj command line tool and add it to your PATH.` ) ;
692
+ }
693
+ }
694
+
667
695
this . $logger . info ( "Installing pods..." ) ;
668
696
let podTool = this . $config . USE_POD_SANDBOX ? "sandbox-pod" : "pod" ;
669
697
let childProcess = this . $childProcess . spawnFromEvent ( podTool , [ "install" ] , "close" , { cwd : this . platformData . projectRoot , stdio : [ 'pipe' , process . stdout , 'pipe' ] } ) . wait ( ) ;
@@ -683,6 +711,11 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
683
711
}
684
712
}
685
713
714
+ if ( shouldUseXcproj ) {
715
+ this . $childProcess . exec ( `xcproj --project ${ this . xcodeprojPath } touch` ) . wait ( ) ;
716
+ this . $childProcess . exec ( `xcproj --project ${ this . cocoaPodsXcodeprojPath } touch` ) . wait ( ) ;
717
+ }
718
+
686
719
return childProcess ;
687
720
} ) . future < any > ( ) ( ) ;
688
721
}
0 commit comments