自动化的一些实践

在不断填坑中前进。。

Posted by 三十一 on July 13, 2017

自动化的一些实践

Xcode版本更新后报错

Xcode9

更新到 Xcode 9 后报错

Error Domain=IDEProvisioningErrorDomain Code=9 ""XXXXXX.app" requires a provisioning profile." UserInfo={NSLocalizedDescription="XXXXXXX.app" requires a provisioning profile., NSLocalizedRecoverySuggestion=Select a provisioning profile for the "Default" build configuration in the project editor.}

参考链接:stackoverflow ,plist 文件内容修改如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
      <key>provisioningProfiles</key>
      <dict>
          <key>MY_APP_BUNDLE_ID</key>
          <string>MY_PROFILE_NAME_AS_SHOWN_BY_XCODE or UUID_FOUND_IN_MOBILEPROVISION_FILE</string>
      </dict>
      <key>method</key>
      <string>development</string>
      <key>uploadBitcode</key>
      <false/>
      <key>uploadSymbols</key>
      <true/>
  </dict>
</plist>

Xcode8.3.3

更新 Xcode 升级到8.3.3 以后,原有打包脚本出错,需要在指定目录添加一个plist文件,现修改如下:

plist 文件内容如下,参考链接 stackoverflow

You’ll have to at least specifiy an entry for method (app-store, ad-hoc, enterprise etc. - defaults to development).

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>method</key>
        <string>development</string>
    </dict>
</plist>


plist 文件需要放在脚本里面 targerIPA_parth 路径下。

打包脚本

今天尝试了下使用脚本自动化打包并发布到蒲公英,现记录如下:

# -*- coding: utf-8 -*-
import os
import sys
import time

#发布到蒲公英的说明文档
updateDescription = ""
# 项目根目录
project_path = ""

#打包证书名称
cerName = ""
#发布证书
#cerName = ""
#工程名称
projectName = ""+".xcodeproj"
#scheme
scheme = ""
# 打包后ipa存储目录
targerIPA_parth = ""



#时间戳
timeStr = time.strftime('%Y-%m-%d%H%M%S',time.localtime(time.time()))
#activePath
activePath = targerIPA_parth +timeStr+".xcarchive"
#蒲公英Key
PGY_key=""
#蒲公英APIKey
PGY_APIkey=""


# 清理项目 创建build目录
def clean_project_mkdir_build():
    print("******clean******")
    os.system('cd %s;xcodebuild clean -project "%s" -scheme %s -configuration release' % (project_path,projectName,scheme)) # clean 项目

def build_project():
    print("build xcarchive start")
    os.system ('xcodebuild -list')
    os.system ('cd %s;xcodebuild archive -project "%s" -scheme %s -configuration release -sdk iphoneos10.3  IPHONEOS_DEPLOYMENT_TARGET=9.0 -archivePath %s;' % (project_path,projectName,scheme,activePath))
    print("build xcarchive end")

# 打包ipa 并且保存在桌面
def build_ipa():
    print("build IPA start")
    os.chdir(targerIPA_parth)
    os.system ('xcodebuild -exportArchive -archivePath %s -exportPath %s -exportOptionsPlist %sIPA.plist'%(activePath,targerIPA_parth,targerIPA_parth))
    print("build IPA end")


def updateIPAToPGY():
    print("开始上传蒲公英")
    os.system ('curl -F \"updateDescription=%s\" -F \"file=@%scopm_cust.ipa\" -F \"uKey=%s\" -F \"_api_key=%s\" https://qiniu-storage.pgyer.com/apiv1/app/upload'%(updateDescription,targerIPA_parth,PGY_key,PGY_APIkey))
    print("上传蒲公英完成")


def updateSVN():
    print("更新SVN数据")
    os.chdir(project_path)    
    os.system ('svn upgrade ')
    os.system ('svn update ')    
    print("更新SVN完成")


def main():
    
    #更新SVN
    updateSVN()
    # 清理并创建build目录
    clean_project_mkdir_build()
    # 编译coocaPods项目文件并 执行编译目录
    build_project()
    # 打包ipa 并制定到桌面
    build_ipa()
    #上传到蒲公英
    updateIPAToPGY()

# 执行
main()