Continous Integretion for Unity

起因

  • 公司有 Unity 專案,需輸出 iOS project 並打包成 ipa 的需求,ipa 有可能是Enterprise program(for BU 測試用),以及 Developer program(上架到 AppStore)

  • 測試期間常重複上述建置動作,相當繁瑣且耗時,思考將流程自動化

建置流程如下

  1. Unity build iOS project

  2. Set iOS project configure, Such as Code sign, Provision Profile, Build Settings etc

  3. Export ipa for Enterprise or Appstore

Unity build iOS project

  • Unity 有 API 專門在處理 iOS Build,先將 Builder.cs 和 XcodeProjectConfigurator.cs 這兩個檔案放到 Unity 專案下的 Assets/Editor裡

  • 進行指令輸出,這邊要注意的是 -projectPath,Folder名稱不能有空白

    /Applications/Unity/Unity.app/Contents/MacOS/Unity \
    -projectPath "/path/to/your/Product" \
    -quit \
    -batchmode \
    -executeMethod "Builder.BuildiOS"
  • 輸出過程不順利,遇到 Plugins coliding with each other 的錯誤訊息,更慘的是第一時間完全沒有 Console 可以看 log~Or2,好在有 log 檔,在 ~/Library/Logs/Unity/Editor.log

  • 查到關鍵的錯誤訊息,解決方法是去調整該檔的 plugin settings,把OS改成OSX就可以了,x64和x86下的VuforiaWrapper.dll都要調

Plugin 'VuforiaWrapper.dll' is used from several locations:
Assets/Plugins/x64/VuforiaWrapper.dll would be copied to <PluginPath>/VuforiaWrapper.dll
Assets/Plugins/x86/VuforiaWrapper.dll would be copied to <PluginPath>/VuforiaWrapper.dll

Please fix plugin settings and try again.

Set iOS project configure

  • Builder.cs 負責 Unity 建置 iOS 專案,在這個檔案裡我額外加了一個設定,把 AutomaticSigning 的功能關掉

    PlayerSettings.iOS.appleEnableAutomaticSigning = false;
  • XcodeProjectConfigurator.cs 在 Build 完之後,針對 iOS build property 進行設定,例如Code Sign 和 Provision_Profile

project.SetBuildProperty(target, "CODE_SIGN_IDENTITY", "iPhone Distribution: XXXXXXXX CO.,LTD.");
project.SetBuildProperty(target, "PROVISIONING_PROFILE", "6999xxxx-1b0f-4c19-be86-62bbb3d6xxxx");

Export ipa for Enterprise or Appstore

desc "Submit a new Beta Build"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    unity(
      execute_method: 'Builder.BuildiOS'
    )    

  provisioningProfiles={"tw.com.xxx.EnterpriseTestApp": "EnterpriseTestApp_InHouse_2018"}

    gym(
        project: './Build/Unity-iPhone.xcodeproj',
        scheme: 'Unity-iPhone',
        export_method: 'enterprise',
        export_options:{provisioningProfiles: provisioningProfiles},
        output_directory: './Build'
    )

Last updated