Cocoapods: Adding xcframework to the app target leading to "Multiple commands produce error" when building test targets.

Created on 31 Mar 2020  Â·  6Comments  Â·  Source: CocoaPods/CocoaPods


🌈

Report

What did you do?

Added the same xcframework to both app and test target
Then ran pod install

What did you expect to happen?

Install all xcframework pod dependencies correctly even in test targets.

What happened instead?

Getting "Multiple commands produce" error when trying to build test.

CocoaPods Environment

Stack

   CocoaPods : 1.9.1
        Ruby : ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
    RubyGems : 3.0.3
        Host : Mac OS X 10.15.2 (19C57)
       Xcode : 11.3 (11C29)
         Git : git version 2.23.0
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
Repositories : master - git - https://github.com/CocoaPods/Specs.git @ 86e1c2c44857465b155f5c428b7e4fc78349c6d5

               trunk - CDN - https://cdn.cocoapods.org/

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-deintegrate : 1.0.4
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.0
cocoapods-stats       : 1.1.0
cocoapods-trunk       : 1.4.1
cocoapods-try         : 1.1.0

Podfile

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'XCFrameworkAppSample' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  pod 'CoconutLib'

  # Pods for XCFrameworkAppSample

  target 'XCFrameworkAppSampleTests' do
    inherit! :search_paths
    pod 'CoconutLib'
    # Pods for testing
  end

  target 'XCFrameworkAppSampleUITests' do
    # Pods for testing
  end

end

Project that demonstrates the issue

When we build the test target, the app target also gets built, since both have their dependencies installed via CocoaPods, both run Prepare Artifact build phase, which creates cocoapods-artifacts-${CONFIGURATION}.txt at the same path(ARTIFACT_LIST_FILE) leading to this error.

XCFrameworkAppSample.zip

xcframeworks confirmed defect

All 6 comments

If you're using inherit! :search_paths then I don't think you need to duplicate the dependency in there - does this not work?

target 'XCFrameworkAppSample' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  pod 'CoconutLib'
  target 'XCFrameworkAppSampleTests' do
    inherit! :search_paths
  end
end

I'm not super familiar with how inherit! :search_paths works under the hood so it's possible XCFrameworks were implemented in a way that broke it

@amorde
I tried removing inherit! :search_paths but still getting the same error.
This error comes when we add same xcframework through the pod to two dependent targets (like the app and the test target in this case) because Prepare Artifacts phase run twice as both the target gets built which creates cocoapods-artifacts-${CONFIGURATION}.txt at the same path(ARTIFACT_LIST_FILE) leading to this error.

Update
I removed all the pod related dependencies from the test target, I found that we don't even need to add xcframework to the test target to reproduce this error. What I mean is that even adding xcframework to the app target can lead to the non-buildability of the test.

Podfile

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'XCFrameworkAppSampleWithoutInheritSearchPath' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  pod 'CoconutLib'

  # Pods for XCFrameworkAppSampleWithoutInheritSearchPath

  target 'XCFrameworkAppSampleWithoutInheritSearchPathTests' do
    # Pods for testing
  end

  target 'XCFrameworkAppSampleWithoutInheritSearchPathUITests' do
    # Pods for testing
  end

end

Sample project:
XCFrameworkAppSampleWithoutInheritSearchPath.zip

Thank you for the example, was able to reproduce.

I'm working on a re-work of the xcframeworks implementation that should fix this

Why do you need to enclose the test targets inside the app target? For me, your test zip runs (and tests) smoothly when I apply the following change to the Podfile:

````
target 'XCFrameworkAppSample' do
use_frameworks!
pod 'CoconutLib'
end

target 'XCFrameworkAppSampleTests' do
inherit! :search_paths
end

target 'XCFrameworkAppSampleUITests' do
end
````

You cannot put pod 'CoconutLib' into the XCFrameworkAppSampleTests, but you don't need that: here is the XCFrameworkAppSampleTests.swift:

````
import XCTest
import CoconutLib
@testable import XCFrameworkAppSample

class XCFrameworkAppSampleTests: XCTestCase {
func testExample() {
print("testExample: (CoconutLibVersionNumber)")
}
}
````

You don't even need inherit! :search_paths to import CoconutLib!

Thanks, @alexcohn for looking into this, I tried the changes in the Podfile that you have suggested in your comment and it solved the issue. Thanks again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

steffendsommer picture steffendsommer  Â·  3Comments

marzapower picture marzapower  Â·  3Comments

lzwjava picture lzwjava  Â·  3Comments

pallaviMN picture pallaviMN  Â·  3Comments

Curtis-Halbrook picture Curtis-Halbrook  Â·  3Comments