使用Jenkins+xcodebuild搭建iOS的持续集成系统

来源:互联网 发布:公司域名备案流程 编辑:程序博客网 时间:2024/06/07 03:26


准备工作:

* 向keychain导入证书,向xcode导入provisioning profile. 都是双击即可导入

* 在xcode中设置bundle id, 这个bundleid需要为将要使用签名的证书允许的.

* signing identity, provision(provisioning profile最好是anySDK也选上,但不知道是不是必须) , 并在preferences中增加对应的开发者账号(增加账号这步不知道是不是必须)


然后通过以下命令行得到工程的配置信息

<span style="font-family:Courier New;">xcodebuild -listInformation about project "Unity-iPhone":    Targets:        Unity-iPhone        Unity-iPhone Tests    Build Configurations:        Release        Debug</span>


*首先到iOS的工程目录


*然后运行如下命令,将工程按照指定的scheme编译成xrchive文件. 我的scheme比较简单,是默认的Unity-iPhone. 所有的certificate, profile, 都是按照xcode中设置选择的

<span style="font-family:Courier New;">xcodebuild -scheme Unity-iPhone -configuration Debug -archivePath build/.xcarchive archive</span>

上面运行的命令行输出中会打印使用的是哪个签名.

如果需要覆盖设置,加入

CODE_SIGN_IDENTITY="iPhone Distribution: Name1 Name2"(这个没有验证过)

PROVISIONING_PROFILE="UDID_Of_Provisioning_Profile"


* 下面导出为ipa, 有两个办法 

第一个办法是实用xcrun. 这个办法通过了测试, 并且可以安装.

<span style="font-family:Courier New;">xcrun -sdk iphoneos  PackageApplication -v build/.xcarchive.xcarchive/Products/Applications/iblis.app -o /Users/xxx/work/LOG/build/ios_release.ipa</span>

如果希望替换企业签名,可以运行如下命令

<span style="font-family:Courier New;">xcrun -sdk iphoneos PackageApplication -v build/.xcarchive.xcarchive/Products/Applications/some.app -o build/ios_release.ipa --sign "iPhone Distribution: Shanghai xxx Science and Technology Co., Ltd" --embed "/Users/cpeng/work/xxx.mobileprovision"</span>


第二个办法是实用xcodebuild

<span style="font-family:Courier New;">xcodebuild -exportArchive -exportFormat IPA -archivePath build/.xcarchive.xcarchive -exportPath build/ios_release.ipa</span>



可能出现的问题:

* 如果导出过程中出现 CSSMERR_TP_NOT_TRUSTED, 可以尝试到苹果网站下载并安装Apple Woldwide Developer Relations Certification Authority证书

下载地址 http://www.apple.com/certificateauthority/, 然后选择

Worldwide Developer Relations - G2 Certificate

WWDR

Root

参考  https://developer.apple.com/legacy/library/technotes/tn2250/_index.html#//apple_ref/doc/uid/DTS40009933-CH1-TNTAG19


* 如果导出ipa过程中出现resource envelope is obsolete, 那么需要修改一下程序运行参数,首先找到PackageApplication的位置

xcrun -sdk iphoneos -f PackageApplication/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication

第一步: 不要使用任何和resource rules有关的东西, 做如下检查. 改为这个, codesign的时候就不报上面的错误了。

- 在buildSetting中去掉resource rules path- 在PackageApplication脚本中去掉 --resource-rules相关(codesign line and do the code signing)- Verify App: codesign --verify -vvvv Payload/*.app

第二步:使用vim去修改里面的运行参数.

my $result = runCmd("/usr/bin/codesign", "--verify", "-vvvv", , $plugin );
my $result = runCmd("/usr/bin/codesign", "--verify", "-vvvv", , $origApp );修改为my $result = runCmd("/usr/bin/codesign", "--verify", "--no-strict", "-vvvv", , $plugin );
my $result = runCmd("/usr/bin/codesign", "--verify", "--no-strict","-vvvv", , $origApp );

* 如果碰到 Program /usr/bin/zip returned 15 : [zip I/O error: No such file or directory的错误,那么应该是在导出的输出目录没有使用绝对路径, 这里不能使用相对路径.

* 记得在login item里面增加企业签名,不要在系统中(在login的tab, 点击+, 然后选择p12)

* 第一次签名,记得询问权限的时候点击一直允许,否则选择私钥然后get info, 然后trust里面选择允许任意.

* 在Jenkins上执行xcodebuild并需要codesign的时候,程序需要用到login.keychain, 这个时候没有询问权限就被自动拒绝了。 解决办法是在jenkins调用xcodebuild之前,利用命令行对login.keychain授权, 否则会报user interaction is not allowed的错误    

security unlock-keychain  -p "your_computer_password" ~/Library/Keychains/login.keychain

----

第一次上面改成功了,后来换了一个证书,一个privioning, 结果运行上面结果也不行了。只能

在keychain里面点击证书的getinfo, 然后标记为始终信任.(改了这个还是这个错误)
在keychain证书里面选择私钥,选择访问控制,选择允许任意程序(在改这个,错误就消失了,编译成功) 
*如果遇到codesign的时候CSSMERR_TP_NOT_TRUSTED,检查以下问题
上面提到的三个苹果certificate网站下载的WWDR, ROOT等证书
确认APP签名整数是绿底白勾。 如果是蓝底白差,可能就会导致这个问题。 确认将证书的trust设置为系统默认,而非所有.
确认app签名certificate里面的的private key是允许所有.
同时在使用codesign之前,需要调用security unlock-keychain 就解决了

*如果遇到codesign的时候,提示user interactive not allowed, 应该是通过ssh调用,并且没有调用security unlock-keychain

1 0
原创粉丝点击