Error while installing Swift Package - unable to access /Package.swift - 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.

Related

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

Editing a Package Dependency as a Local Package

Overview
I have a project that uses a remote swift package.
I would like to edit this package in the same project so that I can refine it based on the usage.
Aim:
To do this I am trying to add the same package as a local package so that I can edit it.
Reference:
https://developer.apple.com/documentation/swift_packages/editing_a_package_dependency_as_a_local_package
Problem:
When I drag and drop the cloned folder containing Package.swift into the project, I can't see any of the local package source files in the project. (see screenshot)
I have been breaking my head over it. Any help on this would be much appreciated.
Xcode Version:
13.2 (13C90) (downloaded from the developer portal not the AppStore)
The reason you cannot see the content of the package is that you have it open in another Xcode instance.
You can only edit a package in one Xcode instance at a time.
I find closing down Xcode completely, then opening up the particular project that I want to edit the package in solves the problem.

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.

Local Swift Packages Stopped Working in Xcode 13

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

How to fix Google Play Services 2 Library install to Eclipse

I've tried to follow https://developer.android.com/google/play-services/setup.html instructions in Eclipse for Mobile Developers (Juno), but am getting multiple errors with the library package after importing the library project into my workspace. I fixed the AndroidManifest.xml error it reported, but now I can't open the project in Eclipse saying the .project description file contains invalid information. So much for a simple install. I've tried uninstalling it, redownloading it, and I still get the multiple errors. Any suggesions how to get it working?
There is a misleading step in step 3 of http://developer.android.com/google/play-services/setup.html:
Copy the
/extras/google/google_play_services/libproject/google-play-services_lib
library project into the source tree where you maintain your Android
app projects.
If you are using Eclipse, import the library project into your
workspace. Click File > Import, select Android > Existing Android Code
into Workspace, and browse to the copy of the library project to
import it.
Don't do the first copy. Instead just do the second part and check the box that says "Copy projects into workspace". I found that if I did the first part I would end up with empty xml files.
Try the following :
https://developers.google.com/maps/documentation/android/intro#sample_code
You would get errors while opening an activity mentioned in the sample code. That is because android.support.v4.app.FragmentActivity is not added to your build path. Hover over the error and click on "Fix Project Setup". It would ask you to add the lib to the build path. Say Yes and enjoy :)
If your google_pay_services/libproject is empty (mine was empty) and looks like installed in sdk manager, first delete google play services from sdk manager, install it again and follow the steps in the first answer.
Try Window > Android SDK Manager > Extras > Google play service > Delete package.
And then re-install that package again:
File > Import, select Android > Existing Android Code into Workspace
I had the same problem. I went to Properties->Java Build Path and clicked on the Projects tab. Then I added google-play-services_lib using the Add button. This got me this run-time exception:
E/AndroidRuntime(9469): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment
So then I changed the main.xml file entry from this:
android:name="com.google.android.gms.maps.MapFragment"
to this:
android:name="com.google.android.gms.maps.SupportMapFragment"
And FINALLY, it runs, but NOW no map due to authorization failure. So I am off on another search.
thanks Google for making it so complicated and for posting incorrect instructions!