Local Swift Packages Stopped Working in Xcode 13 - swift

I've local Swift Packages added to a workspace. They reside in the project subfolders and connected to different git repositories as git submodules. Everything had been working perfectly (the project was able to build, packages were able to resolve, and I could edit the packages within the same workspace).
After I updated Xcode to 13.0, the project started failing to build with multiple errors Missing package product for each local package dependency. Removing derived data, resetting packages, cleaning build folder and restarting Xcode didn't help.

Quit Xcode
Open Terminal
Navigate to the directory where your .xcodeproj is via Terminal (cd path/to/your/apps/folder)
Run xcodebuild -resolvePackageDependencies
After the packages finish resolving, open Xcode and try building again.

This is what worked for me:
Click on the project file then go to Project (not a target) -> Package Dependences tab.
Double-click on any Package and copy the location URL to clipboard.
Remove that Package using the - button.
Add it back, pasting the URL.
Clean Build Folder, then Build.
Alternatively, removing an unused package in the Target -> Build Phases -> Link Binary With Libraries, also removed the errors for me.

Removing package references from workspace and re-adding them (by simple drag-n-drop from Finder) resolved the problem.
I even didn't need to reconfigure corresponding schemes, or re-adding dependencies in targets.

If #lazarevzubov's answer doesn't help, try few additional steps:
Open xcode
Delete one or couple of libs under Build Phases / Link
Binary with Libraries
Discard changes under git
Clean project
Close xcode
Run xcodebuild -resolvePackageDependencies
Open xcode again and try to build

In XCode,
File > Swift Packages > Reset Package Caches

Related

Error while installing Swift Package - unable to access /Package.swift

I recently added a Swift Package (IQKeyboardManager) from GitHub on to my xcworkspace Project. The Package.swift file is in the root folder of the repository. However, I got an error: /Package.swift cannot be accessed
Unable to resolve the error.
How do I fix it?
How do I remove Swift packages?
I tried updating the package a number of time, without luck. As I am not able to delete the package from the Project, I am not even able to run the project now.
To fix this error, you should try the following steps:
Make sure that you have the latest version of Xcode installed on your computer.
Close Xcode and then reopen it.
In Xcode, go to File > Swift Packages > Update to Latest Package Versions.
If the error persists, try removing the package from your project and then re-adding it.
To remove a Swift package from your project, you can use the following steps:
1. Go to the "Project Navigator" in Xcode.
2. Select the package that you want to remove.
3. Press "Delete" on your keyboard.
4. Confirm the deletion.
5. Clean the project (Product > Clean Build Folder)
6. Rebuild the project.
If you are still unable to resolve the issue, it is possible that there may be an issue with the package itself.
You can try checking the package's GitHub page for any known issues or reaching out to the package maintainer for help.

Xcode: Own Swift packages missing in Schema selector

I have some SPM swift packages as part of my swift project.
After some Xcode crashes, those packages don't appear in the Schema selector (black arrow in image) any more.
So I can't select and build the swift packages any more separately.
What can I do to fix this?
For me it was solved by deleting .swiftpm/ folder
(Although, maybe just removing xcshareddata would've been enough)
Steps:
Removing dependency + reference from the main project
Delete .swiftpm/ of "problematic" local package
Add the package dependency back to the project
At least it worked.. Hoping there's a better way to solve this as well.
There must be a better way to resolve this, but at least it works:
Usual housekeeping:
Clear derived data
File -> Packages -> Reset Package Caches
restart Xcode
For each package that Xcode doesn't find / build:
Klick on package -> show in Finder
in finder, move the whole package into a temporary folder (package in Xcode gets red)
delete red package in Xcode
Create package again in Xcode with the same name (File -> New -> Package...), add package to appropriate targets again
remove the newly generated swift files in XCode, including Package.swift
drag the files in your copied folder into the corresponding place in the Xcode package
File -> Packages -> Reset Package Caches (for some reason Xcode loses external packages each iteration)
Build -> should be one less missing package in the error messages

Xcode 13.1 bug editing dependency as local

Just upgraded to Xcode 13.1 and opened a SPM project by clicking the Package.swift file that has some dependencies.
In the former versions I could simply edit one of these dependencies by dragging a local clone of the package into the Project Navigator.
Xcode was then going to ignore the checked out dependency and let me edit the local one.
Apple documents this here.
When trying this with Xcode 13.1, Xcode just copies the folder into the project folder, like it does with normal files/folders that are not SPM projects.
Did I find a bug or missed I something?
Thanks!
Update: I found out how to work around by creating a .xcodeproj file with swift package generate-xcodeproj. There I could drag in the package as always. This works but is not the way to go, as the xcodeproj generation is deprecated by apple.
It looks like there is now an Add Local... button at the bottom of the add package wizard. Selecting the package from your local filesystem yields the same result as the "drag from finder" instructions you've linked.
The wizard is accessible from:
File > Add Packages, or
Project.xcodeproj > Package Dependencies > +.
I was having this problem, too, but after seeing the first comment on the other answer, I tried this:
I used File->Add Packages->Add Local…->navigate to local clone of dependency->Copy Package, which indeed seems to do nothing, but it puts a .package dependency line onto the clipboard.
I then edited my main project’s Package.swift to replace the existing Github dependency with the contents of the clipboard. Now I can edit the dependency’s files directly in the “Package Dependencies” portion of the project contents pane (which I wish you could do for a regular Xcode project too).
This solution kinda sucks, because it forces me to modify Package.swift, which means everyone on the team has to set things up the same way. Fortunately, I'm the only one working on this project, but future me is sure to be bitten by this.

Changes to HTML files not showing on built phonegap 3.0 app

So I have a Phonegap 3.0 app (project folder), and it's project (project/platforms/android) on Eclipse.
The problem is that when I change project/www/index.html , and tell Eclipse to Run the project, the changes don't appear on my device.
I noticed that Eclipse was saying Application already deployed. No need to reinstall. so I tried adding a space in a .java file so that Eclipse would notice some change in the project and rebuild it. It worked, Installing RingTo.apk... Success! showed on the log, but still the changes to index.html didn't show at the device...
Changes made to the files inside project/www/ are not automatically copied to your project (in your case to project/platforms/android/assets/www/). You have to run the following command to iteratively copy the changes to platform specific projects and build them. Open the command prompt and navigate to the root of the project (In this case project/). Or you can even right click on the project/ folder while pressing the shift key. Then run the following command:
cordova build
You can optionally limit the scope of each build to specific platforms:
cordova build android
Alternatively, you can run the following commands:
cordova prepare android
cordova compile android
In this case, once you run prepare, you can use Eclipse with ADT installed as an alternative to modify and compile the "platform-specific code" that Cordova generates within platforms/android.
Source - Cordova Docs
So, when you have made a slight modification in a .java file (which is an android platform specific file) and tried to rebuild it within Eclipse, you were actually trying to rebuild the same project without any actual modifications.
Another alternative would be to copy the files within the project/www/ to project/platforms/android/assets/www/ by hand and then build it within Eclipse, which would, of course, be an unnecessary pain.

Xcode version 4.6.2 (4H1003) compiler error

I just updated to Xcode version 4.6.2 (4H10003) and tried to run a previously working application project in the simulator and received the following error and the build failed.
PCH file built from a different branch ((clang-425.0.27)) than the compiler ((clang-425.0.28))
What went wrong and how can it be fixed?
Do a Clean of the project; hold Option so that you are cleaning out the whole build folder and intermediates. You might have to quit Xcode and throw away the whole contents of the DerivedData folder by hand in the Finder, as I describe here: How to Empty Caches and Clean All Targets Xcode 4
Go to your project's Build Settings, find a setting named Precompiled Headers Cache Path, then delete that folder
Do a cleanup using command+shift+k and run existing project again.
From XCode 4.6.2 Release Notes
Known Issues
Building
When building a product previously built with Xcode 4.6.1 or earlier, the build fails with an error similar to this one:
PCH file built from a different branch ((clang-425.0.27)) than the compiler ((clang-425.0.28))
To address this issue, choose Product > Clean before building your product. 13663167
Performing Product > Clean works
I've tried all the above and it works fine from Xcode UI, but it was still failing for me when I ran xcodebuild from command line.
That was due to dependencies to other libraries and their pre-compile headers. When running from command line, looks like xcodebuild store/reads pre-compiled headers from here:
/var/folders/v0/ztxy9kls7sv05dpmvjgg_xwr0000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders
After cleaning up that folder, xcodebuild succeeded.
Specially if you build from command line or you have a build script, cleaning xcode target is not enough. You have to delete this folder.
The exact location of precompiled header can be found in the project, part of the folder path is random (I guess), esp after /var/folders/xx..xxx/C.
Target -> build settings => "Build locations" -> Precompiled headers cached path
Run Terminal and go to this folder and delete (use command),
#rm -fr SharedPrecompiledHeaders
I had to manually delete ~/Library/Developer/Xcode/DerivedData/
Clean didn't work for me.
use "command+shift+k" to clean your project, then you'll be fine.
Clean Your project and run
Product- > Clean
Then, Run.