Search code examples
iosxcodecocoapodstvosxcodebuild

xcodebuild building both iOS and tvOS targets when only tvOS is requested


I have an Xcode project with 2 targets: one for iOS and one for tvOS. I'm using the following command-line command to build it:

xcodebuild -workspace "/Users/xxx/Code/project.xcworkspace" -scheme "tvOS" -configuration Release -sdk appletvos ONLY_ACTIVE_ARCH=NO BUILD_DIR="/Users/xxx/Library/Developer/Xcode/DerivedData/project-abcdef/Build/Products" BUILD_ROOT="/Users/xxx/Library/Developer/Xcode/DerivedData/project-abcdef/Build/Products" BITCODE_GENERATION_MODE=bitcode ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode"

My project has two dependencies pulled in via CocoaPods with the following Podfile:

use_frameworks!

def common()
    pod 'CocoaLumberjack', '~> 3.5'
    pod 'JSONModel', '~> 1.8'
end

target 'iOS' do
    platform :ios, '9.0'
    common()
    pod 'GoogleAds-IMA-iOS-SDK', '~> 3.9'
end

target 'tvOS' do
    platform :tvos, '9.1'
    common()
    pod 'GoogleAds-IMA-tvOS-SDK', '~> 4.2'
end

When I build the iOS target, it works fine. In the build directory I see something like the following:

Build
  - Intermediates.noindex
  - Products
    - Release-ios
       - project.framework
       - CocoaLumberjack-iOS
       - JSONModel-iOS
       - Pods_project_tvOS.framework

When I build the tvOS target, it's generating both iOS and tvOS versions of dependencies:

Build
  - Intermediates.noindex
  - Products
    - Release-appletvos
       - project.framework
       - CocoaLumberjack-iOS
       - CocoaLumberjack-tvOS
       - JSONModel-iOS
       - JSONModel-tvOS
       - Pods_project_tvOS.framework

I've been trying to figure out why this is happening, as it's leading to additional issues in our build pipeline downstream. So far I've tried:

  • In the Build Settings I noticed that there were "versions" set for various SDKs I wasn't building (e.g. there was a default Apple Watch version, or on the iOS target there was a default tvOS version). I overrode these default versions with blank values for all except the SDK I'm attempting to build
  • Under the Project > Info I noticed that CocoaPods had added "Configurations", with four files like "Pods-project-tvOS.release.xcconfig". I tried modifying my xcodebuild command with -xcconfig "..." (linking to the proper config file) but this led to a build failure, claiming there was now a cycle in dependencies: project-tvOS -> CocoaLumberjack-iOS -> project-tvOS
  • I've tried manually setting the TARGETED_DEVICE_FAMILY to 1,2 or 3 as appropriate
  • I've tried setting ONLY_ACTIVE_ARCH to YES

As a test I built using Xcode (without using the xcodebuild command line tool) and this worked just fine. So there's something wrong with my command. However I can't rely on Xcode to build this project because I need to automatically create a fat binary from a single command - hence I have a shell script calling xcodebuild twice then using lipo to combine the results


Solution

  • This looks like https://github.com/CocoaPods/CocoaPods/issues/8729 which started with Xcode 10.2 which is related to this Apple radar.

    We switched to running our xcodebuild tests with single platform Podfiles.

    Another likely workaround is selecting the old Xcode build system.