How can we configure CI for the iOS app with App Extensions

那年仲夏 提交于 2021-02-11 12:17:58

问题


I have tried multiple things in Azure DevOps (VSTS) to create CI for the iOS app but turns out that Azure DevOps doesn't support the apps that have App extensions. Is it really the case?

I'm using the OneSignal Notification Service Extension in our project which is dependent on the main target. So, when Xcode task tries to sign the app an error occurs related to the build identifiers as the Xcode main target has a different build identifier than OneSignalNotificationServiceExtension's build identifier.

❌ error: Provisioning profile "MainTargetName" has app ID "com.xyz.-", which does not match the bundle ID "com.xyz.-.OneSignalNotificationServiceExtension". (in target 'OneSignalNotificationServiceExtension' from project 'ProjectName')

I'm using an apple certificate task to install the certificates on the Microsoft hosted agent and similarly using the provisioning profile task to install the provisioning profiles. It looks like the Xcode task has a limitation that it cannot get multiple provisioning profiles so it can cater to those iOS apps with App Extension.

- task: InstallAppleCertificate@2
  displayName: 'Install Certificates'
  inputs:
    certSecureFile: '3Certificates.p12'
    certPwd: '$(P12Password)'
    keychain: 'temp'


- task: InstallAppleProvisioningProfile@1
  displayName: 'Install MainTarget provisioning profile'
  inputs:
    provisioningProfileLocation: 'secureFiles'
    provProfileSecureFile: 'MainTarget.mobileprovision'

- task: InstallAppleProvisioningProfile@1
  displayName: 'Install OneSignal provisioning profile'
  inputs:
    provisioningProfileLocation: 'secureFiles'
    provProfileSecureFile: 'OneSignal.mobileprovision'

- task: CmdLine@2
  displayName: 'CocoaPods install'
  inputs:
    script: |
      cd $(Build.SourcesDirectory)
      echo "Pod installation"
      pod install
- task: Xcode@5
  displayName: 'Xcode Build'
  inputs:
    actions: 'build'
    xcWorkspacePath: 'CICD.xcworkspace'
    scheme: 'CICD'
    xcodeVersion: 'specifyPath'
    xcodeDeveloperDir: '/Applications/Xcode_11.2.1.app'
    packageApp: true
    exportOptions: 'plist'
    exportOptionsPlist: 'CICD/Info.plist'
    signingOption: 'manual'
    signingIdentity: '$(MY_CERTIFICATE_SIGN_IDENTITY)'
    provisioningProfileUuid: '$(MainTarget_ProfileUUID)'
    provisioningProfileName: '$(MainTarget_ProfileName)'

Let me know if I'm missing something here.


回答1:


Unfortunately, there is not a straight forward way for the iOS application with App extension in Azure.

  1. To make it work you'll have to do a couple of changes in the project that are recommended on this link.
  2. Afterward, you'll be able to build and archive the application using xcodebuild Docs. because you'll have a variable pointing to each provisioning profile.
  3. On your MAC try xocdebuild command in the terminal and note down the full commands to achieve a specific file.
  4. Use CmdLine@2 task in the pipeline with these commands to build, archive & export your IPA.

Note: I have posted a Gist covering the pipeline for such an iOS application.

- task: InstallAppleCertificate@2
  displayName: 'Install Certificates'
  inputs:
    certSecureFile: '3Certificates.p12'
    certPwd: '$(P12Password)'
    keychain: 'temp'

- task: InstallAppleProvisioningProfile@1
  displayName: 'Install MainTarget provisioning profile'
  inputs:
    provisioningProfileLocation: 'secureFiles'
    provProfileSecureFile: 'MainTarget.mobileprovision'

- task: InstallAppleProvisioningProfile@1
  displayName: 'Install OneSignal provisioning profile'
  inputs:
    provisioningProfileLocation: 'secureFiles'
    provProfileSecureFile: 'OneSignal.mobileprovision'

- task: CmdLine@2
  displayName: 'CocoaPods install'
  inputs:
    script: |
      cd $(Build.SourcesDirectory)
      echo "Pod installation"
      pod install

- task: CmdLine@2
  inputs:    
    script: |
      echo "Build iOS app"
      cd $(Build.SourcesDirectory)
      
      /usr/bin/xcodebuild -sdk $(sdkOption) -configuration $(configurationOption) -workspace $(workspaceName) -scheme "$(schemeName)" build -allowProvisioningUpdates CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="$(signingIdentity)" APP_PROFILE="$(APP_PROFILE_ID)"  EXTENSION_PROFILE="$(APP_EXT_PROFILE_ID)"
  displayName: 'Xcode Buid'

- task: CmdLine@2
  inputs:    
    script: |
      echo "Archive the iOS app"
      cd $(Build.SourcesDirectory)
      
      /usr/bin/xcodebuild -sdk $(sdkOption) -configuration $(configurationOption) -workspace $(workspaceName) -scheme "$(schemeName)" archive -allowProvisioningUpdates CODE_SIGN_STYLE=Manual CODE_SIGN_IDENTITY="$(signingIdentity)" APP_PROFILE="$(APP_PROFILE_ID)"  EXTENSION_PROFILE="$(APP_EXT_PROFILE_ID)" -archivePath $(ArchivePath)
  displayName: 'Xcode Archive'

- task: CmdLine@2
  inputs:    
    script: |
      /usr/bin/xcodebuild -exportArchive -archivePath $(ArchivePath) -exportOptionsPlist $(Build.SourcesDirectory)/MyApplication-Info.plist  -exportPath $(ExportIpaPath)
  displayName: 'Xcode Export'



回答2:


Please check this issue, you can try building the ios App in command-line and pass the extension app name as a parameter.

Something like: xcodebuild ... -scheme "YourExtension" -CODE_SIGN_IDENTITY=xxx PROVISIONING_PROFILE=xxx CONFIGURATION_BUILD_DIR=xxx

For more details about how to build projects from the command line see here.



来源:https://stackoverflow.com/questions/62772507/how-can-we-configure-ci-for-the-ios-app-with-app-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!