Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI Test target does not recognize Swift package from custom framework in xcworkspace

I am developing several projects in a single workspace (monorepo). The workspace contains a shared framework that contains code shared between the projects. Some of the code depends on external packages that I import using the Swift Package Manager. Everything is working except that the packages aren't recognized when I use the UI testing target. When I run the UI tests for one of the projects it complains that the packages cannot be found (in the framework). Another solution that suits my needs is also welcome. Anyway, I'm using Xcode 11.3. To reproduce:

  1. Create a new workspace.
  2. Add a new project A and a new framework B into the workspace.
  3. Add any dependency (for example SDWebImage) to the framework.
  4. Add a Swift-file to the framework that just does import SDWebImage.
  5. Now add framework B as a dependency to project A.

If you build project A or unit test project A, there is no problem. However, when you run UI tests on project A it complains that it cannot find the module SDWebImage in the Swift-file you added in point 4 above. Any idea how to solve this?

Edit: When I use Cocoapods instead it gives me the same error. When I use use_frameworks! it doesn't give me the error, but it crashes with "SDWebImage: image not found".

like image 777
Joris Weimar Avatar asked Jun 14 '20 14:06

Joris Weimar


1 Answers

You have to manually add your B framework as a linked library in on your UI Tests target under Build Phases -> Link Binary With Libraries

like image 76
Alex Terente Avatar answered Oct 21 '22 13:10

Alex Terente