Skip to content

Commit 8d5577e

Browse files
author
minggo
authored
can generate ipa with xcode 8.3+ (#421)
1 parent 6c5488e commit 8d5577e

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

plugins/plugin_compile/project_compile.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,23 +796,30 @@ def build_ios(self):
796796
"\"%s\"" % self.xcworkspace if self.cocoapods else projectPath,
797797
"-configuration",
798798
"%s" % 'Debug' if self._mode == 'debug' else 'Release',
799-
"-scheme" if self.cocoapods else "-target",
799+
"-scheme",
800800
"\"%s\"" % targetName,
801801
"%s" % "-arch i386" if self.use_sdk == 'iphonesimulator' else '',
802802
"-sdk",
803803
"%s" % self.use_sdk,
804804
"CONFIGURATION_BUILD_DIR=\"%s\"" % (output_dir),
805805
"%s" % "VALID_ARCHS=\"i386\"" if self.use_sdk == 'iphonesimulator' else ''
806806
])
807+
808+
# PackageApplication is removed since xcode 8.3, should use new method to generate .ipa
809+
# should generate .xcarchive first, then generate .ipa
810+
use_new_ipa_method = float(cocos.get_xcode_version()) >= 8.3
807811

808812
if self._sign_id is not None:
809-
command = "%s CODE_SIGN_IDENTITY=\"%s\"" % (command, self._sign_id)
813+
if use_new_ipa_method:
814+
archive_path = os.path.join(output_dir, "%s.xcarchive" % targetName)
815+
command = "%s CODE_SIGN_IDENTITY=\"%s\" -archivePath %s archive" % (command, self._sign_id, archive_path)
816+
else:
817+
command = "%s CODE_SIGN_IDENTITY=\"%s\"" % (command, self._sign_id)
810818

811819
command = self.append_xcpretty_if_installed(command)
812820
self._run_cmd(command)
813821

814822
filelist = os.listdir(output_dir)
815-
816823
for filename in filelist:
817824
name, extention = os.path.splitext(filename)
818825
if extention == '.a':
@@ -825,13 +832,22 @@ def build_ios(self):
825832

826833
if self._sign_id is not None:
827834
# generate the ipa
828-
app_path = os.path.join(output_dir, "%s.app" % targetName)
829835
ipa_path = os.path.join(output_dir, "%s.ipa" % targetName)
830-
ipa_cmd = "xcrun -sdk %s PackageApplication -v \"%s\" -o \"%s\"" % (self.use_sdk, app_path, ipa_path)
831-
self._run_cmd(ipa_cmd)
836+
if use_new_ipa_method:
837+
# generate exportoptions.plist file if needed
838+
export_options_plist_path = os.path.join(output_dir, "exportoptions.plist")
839+
self._generate_export_options_plist(export_options_plist_path)
840+
841+
archive_path = os.path.join(output_dir, "%s.xcarchive" % targetName)
842+
ipa_cmd = "xcodebuild -exportArchive -archivePath %s -exportPath %s -exportOptionsPlist %s" % (archive_path, output_dir, export_options_plist_path)
843+
self._run_cmd(ipa_cmd)
844+
else:
845+
ipa_cmd = "xcrun -sdk %s PackageApplication -v \"%s\" -o \"%s\"" % (self.use_sdk, self._iosapp_path, ipa_path)
846+
self._run_cmd(ipa_cmd)
832847

833848
cocos.Logging.info(MultiLanguage.get_string('COMPILE_INFO_BUILD_SUCCEED'))
834-
except:
849+
except Exception, e:
850+
print str(e)
835851
raise cocos.CCPluginError(MultiLanguage.get_string('COMPILE_ERROR_BUILD_FAILED'),
836852
cocos.CCPluginError.ERROR_BUILD_FAILED)
837853
finally:
@@ -845,6 +861,32 @@ def build_ios(self):
845861
if engine_js_dir is not None:
846862
self.reset_backup_dir(engine_js_dir)
847863

864+
def _generate_export_options_plist(self, export_options_plist_path):
865+
if os.path.exists(export_options_plist_path):
866+
return
867+
868+
file_content_head = """
869+
<?xml version="1.0" encoding="UTF-8"?>
870+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
871+
<plist version="1.0">
872+
<dict>
873+
<key>compileBitcode</key>
874+
<false/>
875+
"""
876+
877+
# should use add-hoc for release mode?
878+
method = "app-store" if self._mode == 'release' else "development"
879+
method_content = "<key>method</key>\n<string>%s</string>" % method
880+
881+
file_content_end = """
882+
</dict>
883+
</plist>
884+
"""
885+
886+
file_content = file_content_head + method_content + file_content_end
887+
with open(export_options_plist_path, 'w') as outfile:
888+
outfile.write(file_content)
889+
848890
def build_mac(self):
849891
if not self._platforms.is_mac_active():
850892
return

0 commit comments

Comments
 (0)