Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'no such module' error when importing a Swift Package Manager dependency

I'm running Xcode 11 Beta 4. I'm using CocoaPods, and wanted to use one of my dependencies with Swift Package Manager as a static library instead of as a framework. On a fresh project created with Xcode 11, the dependency can be imported successfully, but on my existing CocoaPods workspace, it does not.

I think it's likely related, but I'm also getting this link warning in Xcode:

directory not found for option '-L/Users/username/Library/Developer/Xcode/DerivedData/App-axanznliwntexmdfdskitsxlfypz/Build/Products/Release-iphoneos 

I went to see if the directory exists after the warning is emitted, and it does. I could not find any meaningful difference between the newly-created project and my old one, other than the existence of CocoaPods.

Would appreciate any pointers.

like image 499
Adar Hefer Avatar asked Jul 23 '19 13:07

Adar Hefer


People also ask

How do I add package manager to Swift?

To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter its repository URL.

Where are Swift package dependencies stored?

In order to cache the dependencies, they should be located in the project directory, but by default, SPM downloads the dependencies into the system folder: ~/Library/Developer/Xcode/DerivedData.

Can I use a CocoaPods dependency with Swift Package Manager?

I'm using CocoaPods, and wanted to use one of my dependencies with Swift Package Manager as a static library instead of as a framework. On a fresh project created with Xcode 11, the dependency can be imported successfully, but on my existing CocoaPods workspace, it does not.

Can Xcode compile SPM dependencies as Swift modules?

I realised Xcode compile SPM dependencies as Swift modules and add the files in Build/Products/Release-iphoneos folder in DeriverData. So I created a scheme in Xcode and added this run script on build pre-actions:

Does Swift Package Manager implicitly depend on configuration names?

It turned out that Swift Package Manager implicitly depends on the project's Configuration names. I had them at live/qa instead of Release/Debug, and changing them back resolved the issue.

How to add faswiftui library in Swift import statement?

After adding a library (FASwiftUI in my case) through Swift Package Manager I had to add it to Project Settings -> General -> My Target -> Frameworks, Libraries, and Embedded Content to be visible in the import statement. I did not add any scripts for it to work. Show activity on this post.


2 Answers

After adding a library (FASwiftUI in my case) through Swift Package Manager I had to add it to

Project Settings -> General -> My Target -> Frameworks, Libraries, and Embedded Content

to be visible in the import statement.

I did not add any scripts for it to work.

enter image description here

like image 62
Jerzy Kiler Avatar answered Sep 18 '22 16:09

Jerzy Kiler


Based on @AlexandreMorgado answer it seems like it is better to run this script in Build phases before Compile Sources. Then it works when archiving.

enter image description here

if [ -d "${SYMROOT}/Release${EFFECTIVE_PLATFORM_NAME}/" ] && [ "${SYMROOT}/Release${EFFECTIVE_PLATFORM_NAME}/" != "${SYMROOT}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/" ]  then   cp -f -R "${SYMROOT}/Release${EFFECTIVE_PLATFORM_NAME}/" "${SYMROOT}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/" fi 
like image 23
sliwinski.lukas Avatar answered Sep 21 '22 16:09

sliwinski.lukas