SolvedCocoaPods Unit tests do not run on iOS 11 devices on Xcode 11 when using dynamically linked libraries

Report

What did you do?

I built a simple app that has 2 unit tests and 2 ui tests in Xcode 11 GM Seed 2. Its minimum deployment target is 11.0. I indicated that I want to use Cocoa Touch Frameworks in both my App target and Unit Test target, by declaring use_frameworks! under both targets in the Podfile.

What did you expect to happen?

I expect to be able to build, and run both unit and ui tests successfully for iOS 11, 12, and 13 simulators and devices.

What happened instead?

The project compiles but does not run unit or ui tests on any iOS 11 version simulator. This includes iOS versions 11.0, 11.1, 11.2, 11.3, 11.4. This is the error message:
2019-09-18 11:45:49.838967-0400 xctest[33269:1591375] The bundle “TestAppTests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. 2019-09-18 11:45:49.839132-0400 xctest[33269:1591375] (dlopen_preflight(/Users/dvataksi/Library/Developer/Xcode/DerivedData/TestApp-dudbjerumgardlbyxjegkcjhkdiq/Build/Products/Debug-iphonesimulator/TestAppTests.xctest/TestAppTests): Library not loaded: @rpath/libswiftCoreGraphics.dylib Referenced from: /Applications/Xcode_11_GM2.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/lib/libXCTestSwiftSupport.dylib Reason: no suitable image found. Did find: /usr/lib/swift/libswiftCoreGraphics.dylib: mach-o, but not built for iOS simulator /usr/lib/swift/libswiftCoreGraphics.dylib: mach-o, but not built for iOS simulator) Program ended with exit code: 82

CocoaPods Environment

Stack

   CocoaPods : 1.7.5
        Ruby : ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]
    RubyGems : 3.0.6
        Host : Mac OS X 10.14.6 (18G87)
       Xcode : 10.3 (10G8)
         Git : git version 2.17.1
Ruby lib dir : /Users/myusername/.rbenv/versions/2.5.1/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ 68612e4c07451e618fd1beb8d6b708fa34385081

Installation Source

Executable Path: /Users/myusername/.rbenv/versions/2.5.1/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.3.1
cocoapods-try         : 1.1.0

Project that demonstrates the issue

Download the demo project here -> https://github.com/dvataksi16/TestApp

38 Answers

✔️Accepted Answer

@dvataksi16 I got a response from Apple with a non-hacky solution:

After reviewing your feedback, we have some additional information for you.

Since Xcode 11, you should be linking against libXCTestSwiftSupport.dylib instead of the old libswiftXCTest.dylib which is obsolete. The set of symbols exported by the new library should be nearly identical.

Which means your "Other linker flags" should be -weak_framework XCTEST -weak-lXCTestSwiftSupport

And you should add $(PLATFORM_DIR)/Developer/usr/lib to your "Library search path"

Other Answers:

I'm experiencing the same issue as described by @dvataksi16. Unit Tests are working fine on iOS 13, but are failing iOS 11.

@dnkoutso, Given Apple's response to @Cyberbeni, is it possible that Cocoapods needs to be updated to deal with making sure to link against XCTestSwiftSupport?

More Issues: