Skip to content

Commit 6482ba8

Browse files
author
minggo
authored
fix archive issue with Xcode 9 (#431)
1 parent 8a7babb commit 6482ba8

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

plugins/plugin_compile/project_compile.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,15 @@ def build_ios(self):
759759
if os.path.isdir(output_dir):
760760
target_app_dir = os.path.join(output_dir, "%s.app" % targetName)
761761
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)
763771

764772
# is script project, check whether compile scripts or not
765773
need_reset_dir = False
@@ -790,13 +798,18 @@ def build_ios(self):
790798
try:
791799
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_BUILDING'))
792800

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+
793806
command = ' '.join([
794807
"xcodebuild",
795808
"-workspace" if self.cocoapods else "-project",
796809
"\"%s\"" % self.xcworkspace if self.cocoapods else projectPath,
797810
"-configuration",
798811
"%s" % 'Debug' if self._mode == 'debug' else 'Release',
799-
"-scheme" if self.cocoapods else "-target",
812+
"-scheme" if use_scheme else "-target",
800813
"\"%s\"" % targetName,
801814
"%s" % "-arch i386" if self.use_sdk == 'iphonesimulator' else '',
802815
"-sdk",
@@ -807,14 +820,12 @@ def build_ios(self):
807820

808821
# PackageApplication is removed since xcode 8.3, should use new method to generate .ipa
809822
# should generate .xcarchive first, then generate .ipa
810-
xcode_version = cocos.get_xcode_version()
811-
812823
use_new_ipa_method = cocos.version_compare(xcode_version,">=",8.3)
813824

814825
if self._sign_id is not None:
815826
if use_new_ipa_method:
816827
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)
818829
else:
819830
command = "%s CODE_SIGN_IDENTITY=\"%s\"" % (command, self._sign_id)
820831

@@ -836,12 +847,15 @@ def build_ios(self):
836847
# generate the ipa
837848
ipa_path = os.path.join(output_dir, "%s.ipa" % targetName)
838849
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+
842856

843857
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)
845859
self._run_cmd(ipa_cmd)
846860
else:
847861
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):
863877
if engine_js_dir is not None:
864878
self.reset_backup_dir(engine_js_dir)
865879

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
869892

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')
891894

892895
def build_mac(self):
893896
if not self._platforms.is_mac_active():

0 commit comments

Comments
 (0)