美文网首页
基于xcode8自动打包python脚本

基于xcode8自动打包python脚本

作者: Simon_____ | 来源:发表于2017-05-04 13:41 被阅读0次

    最近老板兴起,想搞个快速可复制交付的东西,简言之就是在平台填些配置信息(display name,bundle id,version code),然后点点鼠标,就生成另外一个应用,一开始也是一脸懵逼,然后各种撕逼,后来还是做成了。话不多说,先来说说过程中遇到的坑们。

    一、脚本
    我这边选的是python脚本,这之前也是py小白,后来找了廖雪峰老师的py教程学习了下基本语法,在网上也找了些写好的脚本,但是貌似xcode8以后就有点变动了。主要是参照CaryaLiu大神的写的py脚本
    down下来(大神文章中有下载)填下相关参数直接放在项目中跑,最后一步export failed

    执行脚本export failed
          ./autobuild.py -p Test.xcodeproj -s Test 执行脚本及相关参数
    

    Error Domain=IDEDistributionErrorDomain Code=14 "No applicable devices found." UserInfo={NSLocalizedDescription=No applicable devices found.}
    后来几经百度,Google找到了大神的回答,就稍稍的修改了下脚本,因为我这边demo没有用cocoapods,所以就是buildProject,workspace类似修改即可。

    修改前:

    def exportArchive(scheme, archivePath):
        exportDirectory = buildExportDirectory(scheme)
        exportCmd = "xcodebuild -exportArchive -archivePath %s -exportPath %s -exportOptionsPlist %s" %(archivePath, exportDirectory, EXPORT_OPTIONS_PLIST)
        process = subprocess.Popen(exportCmd, shell=True)
        (stdoutdata, stderrdata) = process.communicate()
    
        signReturnCode = process.returncode
        if signReturnCode != 0:
            print "export %s failed" %(scheme)
            return ""
        else:
            return exportDirectory
    
    def buildProject(project, scheme):
        archivePath = buildArchivePath(scheme)
        print "archivePath: " + archivePath
        archiveCmd = 'xcodebuild -project %s -scheme %s -configuration %s archive -archivePath %s -destination generic/platform=iOS' %(project, scheme, CONFIGURATION, archivePath)
        process = subprocess.Popen(archiveCmd, shell=True)
        process.wait()
    
        archiveReturnCode = process.returncode
        if archiveReturnCode != 0:
            print "archive workspace %s failed" %(workspace)
            cleanArchiveFile(archivePath)
        else:
            exportDirectory = exportArchive(scheme, archivePath)
            cleanArchiveFile(archivePath)
            if exportDirectory != "":       
                ipaPath = getIpaPath(exportDirectory)
                uploadIpaToPgyer(ipaPath)
    

    修改后:将脚本之前的默认导出路径改在了工程目录build下面

    def exportArchive(scheme, archivePath):
            exportDirectory = buildExportDirectory(scheme)
            exportCmd = "pushd build && mkdir ./Payload && cp  -R `pwd`/%s-iphoneos/%s.app  ./Payload && zip -qyr %s.ipa ./Payload && rm -r ./Payload && popd" %(CONFIGURATION,scheme,exportDirectory)
        process = subprocess.Popen(exportCmd, shell=True)
        (stdoutdata, stderrdata) = process.communicate()
    
        signReturnCode = process.returncode
        if signReturnCode != 0:
            print "export %s failed" %(scheme)
            return ""
        else:
            return exportDirectory
    def buildProject(project, scheme):
        archivePath = buildArchivePath(scheme)
        print "archivePath: " + archivePath
        archiveCmd = 'xcodebuild -project %s -target %s -configuration %s' %(project, scheme, CONFIGURATION)
        process = subprocess.Popen(archiveCmd, shell=True)
        process.wait()
    
        archiveReturnCode = process.returncode
        if archiveReturnCode != 0:
            print "archive workspace %s failed" %(workspace)
            cleanArchiveFile(archivePath)
        else:
            exportDirectory = exportArchive(scheme, archivePath)
            cleanArchiveFile(archivePath)
            if exportDirectory != "":       
                ipaPath = getIpaPath(exportDirectory)
                uploadIpaToPgyer(ipaPath)
    

    修改之后便可在工程目录下生成相应ipa文件。
    第一次发文,写的比较凌乱,见谅语文是数学老师教的,如有疏漏多指教!!
    后期有时间再分享下打包前修改工程配置参数。

    相关文章

      网友评论

          本文标题:基于xcode8自动打包python脚本

          本文链接:https://www.haomeiwen.com/subject/mcirtxtx.html