xcodebuild fails until pod installing again(twice) after the failure occurs - how to resolve?

Viewed 95

I'm setting up github actions to test my xcode app (kotlin multiplatform) and for some reason my build is not successful until pod installing a second time after attempting to build.

So I pod install -> build -> build fails -> pod install again -> build -> build succeeds.

Steps to reproduce this locally:

  • Checkout the repo
  • arch -x86_64 pod install
  • xcodebuild ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO -workspace myworkspace.xcworkspace -scheme myScheme -configuration Release -destination 'platform=iOS Simulator,name=iPhone 12,OS=15.4'

The build fails on this step trying to import the common kotlin library:

import common
       ^

** BUILD FAILED **

and then if I run these steps again

  • arch -x86_64 pod install
  • xcodebuild ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO -workspace myworkspace.xcworkspace -scheme myScheme -configuration Release -destination 'platform=iOS Simulator,name=iPhone 12,OS=15.4'

the build is successful

    /usr/bin/codesign --force --sign - --entitlements /Users/me/Library/Developer/Xcode/DerivedData/myApp-esecylpzfadofbsakhxtkqqgzuk/Build/Intermediates.noindex/myApp.build/Release-iphonesimulator/myApp.build/myApp.app.xcent --timestamp\=none --generate-entitlement-der /Users/me/Library/Developer/Xcode/DerivedData/myApp-esecylpzfadofbsakhxtkqqgzuk/Build/Products/Release-iphonesimulator/myApp.app

** BUILD SUCCEEDED **

Here is my podfile:


platform :ios, '15.2'
use_frameworks!
inhibit_all_warnings!

def shared_pods
    pod 'common', :path => '../common'
    pod 'GoogleSignIn'
end

target 'myApp' do
    shared_pods
end


target 'myApp_Tests' do
    shared_pods
end


post_install do |installer|
     installer.pods_project.targets.each do |target|
         target.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
         end
     end
end

and here's my BuildTests.yaml file for github actions

name: ios-unit-tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  run_tests:
    runs-on: macos-latest
    strategy:
      matrix:
        include:
          - ios: "15.2"
    name: test iOS (${{ matrix.ios }})
    steps:
    - uses: actions/setup-java@v2
      with:
        distribution: 'temurin'
        java-version: '11'
    - name: Checkout repository
      uses: actions/checkout@v3
    - name: Install the Apple certificate and provisioning profile
      env:
        BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }}
        P12_PASSWORD: ${{ secrets.P12_PASSWORD }}
        BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }}
        KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
      run: |
        # create variables
        CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
        PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision
        KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db

        # import certificate and provisioning profile from secrets
        echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode --output $CERTIFICATE_PATH
        echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode --output $PP_PATH

        # create temporary keychain
        security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
        security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
        security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH

        # import certificate to keychain
        security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
        security list-keychain -d user -s $KEYCHAIN_PATH

        # apply provisioning profile
        mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
        cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles

    - name: Install M1 Pod
      run: sudo arch -x86_64 gem install ffi;
    - name: Pod Install
      run: cd myApp; which pod; rm myApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved; arch -x86_64 pod install

    - name: Build
      run: xcodebuild ARCHS=x86_64 ONLY_ACTIVE_ARCH=NO -workspace myApp/myApp.xcworkspace -scheme myApp -configuration Release -destination 'platform=iOS Simulator,name=iPhone 12,OS=${{ matrix.ios }}'

    - name: Run unit tests
      run: xcodebuild test -workspace myApp/myApp.xcworkspace -scheme myApp -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12,OS=${{ matrix.ios }}'



UPDATE: Resolution was to delete .gitignore and build the project and see which files changed. Turned out there were some build files commented out that should have been committed

0 Answers
Related