@@ -759,7 +759,15 @@ def build_ios(self):
759
759
if os .path .isdir (output_dir ):
760
760
target_app_dir = os .path .join (output_dir , "%s.app" % targetName )
761
761
if os .path .isdir (target_app_dir ):
762
- shutil .rmtree (target_app_dir )
762
+ if os .path .islink (target_app_dir ):
763
+ os .unlink (target_app_dir )
764
+ else :
765
+ shutil .rmtree (target_app_dir )
766
+ elif os .path .isfile (target_app_dir ):
767
+ if os .path .islink (target_app_dir ):
768
+ os .unlink (target_app_dir )
769
+ else :
770
+ os .remove (target_app_dir )
763
771
764
772
# is script project, check whether compile scripts or not
765
773
need_reset_dir = False
@@ -790,13 +798,18 @@ def build_ios(self):
790
798
try :
791
799
cocos .Logging .info (MultiLanguage .get_string ('COMPILE_INFO_BUILDING' ))
792
800
801
+ xcode_version = cocos .get_xcode_version ()
802
+ xcode9_and_upper = cocos .version_compare (xcode_version ,">=" ,9 )
803
+ # Xcode 9+ need to use `-scheme`
804
+ use_scheme = self .cocoapods or ( xcode9_and_upper and self ._sign_id )
805
+
793
806
command = ' ' .join ([
794
807
"xcodebuild" ,
795
808
"-workspace" if self .cocoapods else "-project" ,
796
809
"\" %s\" " % self .xcworkspace if self .cocoapods else projectPath ,
797
810
"-configuration" ,
798
811
"%s" % 'Debug' if self ._mode == 'debug' else 'Release' ,
799
- "-scheme" if self . cocoapods else "-target" ,
812
+ "-scheme" if use_scheme else "-target" ,
800
813
"\" %s\" " % targetName ,
801
814
"%s" % "-arch i386" if self .use_sdk == 'iphonesimulator' else '' ,
802
815
"-sdk" ,
@@ -807,14 +820,12 @@ def build_ios(self):
807
820
808
821
# PackageApplication is removed since xcode 8.3, should use new method to generate .ipa
809
822
# should generate .xcarchive first, then generate .ipa
810
- xcode_version = cocos .get_xcode_version ()
811
-
812
823
use_new_ipa_method = cocos .version_compare (xcode_version ,">=" ,8.3 )
813
824
814
825
if self ._sign_id is not None :
815
826
if use_new_ipa_method :
816
827
archive_path = os .path .join (output_dir , "%s.xcarchive" % targetName )
817
- command = "%s CODE_SIGN_IDENTITY=\" %s\" -archivePath %s archive" % (command , self ._sign_id , archive_path )
828
+ command = "%s CODE_SIGN_IDENTITY=\" %s\" -archivePath '%s' archive" % (command , self ._sign_id , archive_path )
818
829
else :
819
830
command = "%s CODE_SIGN_IDENTITY=\" %s\" " % (command , self ._sign_id )
820
831
@@ -836,12 +847,15 @@ def build_ios(self):
836
847
# generate the ipa
837
848
ipa_path = os .path .join (output_dir , "%s.ipa" % targetName )
838
849
if use_new_ipa_method :
839
- # generate exportoptions.plist file if needed
840
- export_options_plist_path = os .path .join (output_dir , "exportoptions.plist" )
841
- self ._generate_export_options_plist (export_options_plist_path )
850
+ # find the path of `exportoptions.plist`
851
+ export_options_path = self ._get_export_options_plist_path ()
852
+ if export_options_path is None :
853
+ cocos .Logging .error ('Can not find exportoptions.plist.' )
854
+ raise Exception ('Can not find exportoptions.plist.' )
855
+
842
856
843
857
archive_path = os .path .join (output_dir , "%s.xcarchive" % targetName )
844
- ipa_cmd = "xcodebuild -exportArchive -archivePath %s -exportPath %s -exportOptionsPlist %s " % (archive_path , output_dir , export_options_plist_path )
858
+ ipa_cmd = "xcodebuild -exportArchive -archivePath '%s' -exportPath '%s' -exportOptionsPlist '%s' " % (archive_path , output_dir , export_options_path )
845
859
self ._run_cmd (ipa_cmd )
846
860
else :
847
861
ipa_cmd = "xcrun -sdk %s PackageApplication -v \" %s\" -o \" %s\" " % (self .use_sdk , self ._iosapp_path , ipa_path )
@@ -863,31 +877,20 @@ def build_ios(self):
863
877
if engine_js_dir is not None :
864
878
self .reset_backup_dir (engine_js_dir )
865
879
866
- def _generate_export_options_plist (self , export_options_plist_path ):
867
- if os .path .exists (export_options_plist_path ):
868
- return
880
+ def _get_export_options_plist_path (self ):
881
+ project_dir = self ._project .get_project_dir ()
882
+
883
+ possible_sub_paths = [ 'proj.ios' , 'proj.ios_mac/ios' , 'frameworks/runtime-src/proj.ios_mac/ios' ]
884
+ ios_project_dir = None
885
+ for sub_path in possible_sub_paths :
886
+ ios_project_dir = os .path .join (project_dir , sub_path )
887
+ if os .path .exists (ios_project_dir ):
888
+ break
889
+
890
+ if ios_project_dir is None :
891
+ return None
869
892
870
- file_content_head = """
871
- <?xml version="1.0" encoding="UTF-8"?>
872
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
873
- <plist version="1.0">
874
- <dict>
875
- <key>compileBitcode</key>
876
- <false/>
877
- """
878
-
879
- # should use add-hoc for release mode?
880
- method = "app-store" if self ._mode == 'release' else "development"
881
- method_content = "<key>method</key>\n <string>%s</string>" % method
882
-
883
- file_content_end = """
884
- </dict>
885
- </plist>
886
- """
887
-
888
- file_content = file_content_head + method_content + file_content_end
889
- with open (export_options_plist_path , 'w' ) as outfile :
890
- outfile .write (file_content )
893
+ return os .path .join (ios_project_dir , 'exportOptions.plist' )
891
894
892
895
def build_mac (self ):
893
896
if not self ._platforms .is_mac_active ():
0 commit comments