Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Package Manager support #1150

Open
navaronbracke opened this issue Aug 15, 2024 · 20 comments
Open

Swift Package Manager support #1150

navaronbracke opened this issue Aug 15, 2024 · 20 comments
Assignees
Labels
ios Platform iOS macos Platform macos

Comments

@navaronbracke
Copy link
Collaborator

Flutter will eventually deprecate and then remove support for CocoaPods. We should add Swift Package Manager support instead.

Migration guide here: https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors#how-to-add-swift-package-manager-support-to-an-existing-flutter-plugin

Why is Flutter migrating to Swift Package Manager?

CocoaPods is now in maintenance mode.

Swift Package Manager support is one of Flutter’s most requested features: flutter#33850.

Flutter's Swift Package Manager integration has several benefits:

  1. Access to the Swift package ecosystem. Flutter plugins can use the growing ecosystem of Swift packages.
  2. Simplifies Flutter installation. Swift Package Manager is bundled with Xcode. In the future, you won’t need to install Ruby and CocoaPods to target iOS or macOS.
@navaronbracke navaronbracke added ios Platform iOS macos Platform macos labels Aug 15, 2024
@navaronbracke navaronbracke self-assigned this Aug 15, 2024
@Xa69
Copy link

Xa69 commented Aug 17, 2024

@navaronbracke are you working on this change? Or can I give it a shot?

@navaronbracke
Copy link
Collaborator Author

I was planning on taking this up, but haven't gotten around to doing so yet. Feel free to take this up!

Also, if you think that doing #782 first, would make things easier, feel free to do so! And if not, we can revisit that one later.

@navaronbracke navaronbracke assigned Xa69 and unassigned navaronbracke Aug 17, 2024
@Xa69
Copy link

Xa69 commented Aug 18, 2024

@navaronbracke I'll give this one a try first

@Xa69
Copy link

Xa69 commented Aug 18, 2024

@navaronbracke I followed the documentation mentioned in the work item and made the appropriate changes.

If we migrate to swift package manager, I’m encountering an error "Parse Issue (Xcode): Module 'image_picker_ios' not found” this seems to be a common issue with this module when we switch over to swift package manager.

Found an open issue in Git : flutter/flutter#152550

These new changes will not affect the existing Cocoapods installation and build process.

The plugin works fine when run with the flag "flutter config --no-enable-swift-package-manager” after adding the SPM changes.

Issue only comes up when we run with "flutter config --enable-swift-package-manager”.

We can try removing this module and attempting to build but I’m not sure if this is a viable solution as it might remove a functionality from the plugin.

Changes are present here : https:/Xa69/mobile_scanner/tree/users/nimish/1150-SPM-Support-Changes

Let me know if I should try by removing the module itself.

@navaronbracke
Copy link
Collaborator Author

navaronbracke commented Aug 18, 2024

Good finding! I had a look and I see that flutter/packages#6833 is a reland of Swift Package Manager support for that plugin. (the first attempt was reverted due to the issue you found)

I see that the pubspec of our example does not use the latest version of image_picker.

image_picker_ios version 0.8.12 should fix that, but I'm not sure if the latest version of image_picker already uses that version.

You could try the following:

  1. Bump the example's image_picker dependency to the latest version (image_picker: ^1.1.2)
  2. If step 1 still does not fix the issue, depend on image_picker_ios: ^0.8.12 as well (so depend on both image_picker and image_picker_ios in the example pubspec) Also add a note to remove the image_picker_ios dependency when image_picker can be upgraded to use that version (without us having to explicitly depend on it)

@Xa69
Copy link

Xa69 commented Aug 18, 2024

Tried with both solutions suggested, observing the same error when trying with SPM

@navaronbracke
Copy link
Collaborator Author

Hmm, since the conversation in that other issue is still ongoing (they asked for some things in a reproducible sample's iOS project to investigate further), I do suggest we turn off the image_picker part of the example, with a link to that issue, so we can re-enable it later (for people that are using SPM).

@Xa69
Copy link

Xa69 commented Aug 18, 2024

Alright then I’ll try to figure out how to go about doing that and push the changes to the same branch.

@Xa69
Copy link

Xa69 commented Aug 18, 2024

@navaronbracke After removing the image_picker from the pubspec.yaml file in the ‘example’ directory for iOS, I’m getting this build error :
Error (Xcode): Error: Couldn't resolve the package 'image_picker' in 'package:image_picker/image_picker.dart’.

I’m not able to figure out where else the image_picker is used from the universal search or going through the directories.
Would appreciate any help on where to go.

@navaronbracke
Copy link
Collaborator Author

AFAIK we only use it here in the example, but nowhere else in this repository: https:/juliansteenbakker/mobile_scanner/blob/master/example/lib/scanner_button_widgets.dart

Perhaps doing a flutter clean and/or cleaning the XCode build directory from within XCode itself and rebuilding the example app fixes it?

@Xa69
Copy link

Xa69 commented Aug 19, 2024

@navaronbracke The steps you suggested did work, surprised VS code didn’t find it’s usage.

I have a concern regarding disabling the use of image picker, this will affect users irrespective of whether they’re building using Cocoapods or SPM.

I’d suggest we proceed with this change once the image_picker_ios issue is resolved to prevent blocking users from utilising the feature.

I did try what you suggested and I’m getting an error 'Module ‘integration_test’ not found' now this can be resolved I believe but since I had the query wanted to confirm if it’s a good idea to proceed with this change at this time?

@navaronbracke
Copy link
Collaborator Author

Perhaps you had filters on that excluded files when searching in VS Code?

I do agree, perhaps we should wait until image_picker releases a version that depends on that image_picker_ios version. Although, this would only affect our example app, but it is still a valid concern.

For integration_test, that should be vendored by the Flutter SDK itself, and should be kept under the dev dependencies.
See https://docs.flutter.dev/release/breaking-changes/flutter-driver-migration#setup

I'm not sure why that would be causing a problem, though? Perhaps because integration_test itself isn't migrated to SPM? Or was it a stale build on your end?

Regarding your contribution, I would propose that you already open up the pull request as a draft. Then I can take a look at it, and you won't lose the work (as it exists on a remote then)

@Xa69
Copy link

Xa69 commented Aug 19, 2024

@navaronbracke I’m not entirely sure why integration_test is throwing the error because we already have the dev_dependency included in the pubspec.yaml. It is possible that this issue is only occurring on my system as I have set up flutter for the first time or could require a transition to SPM but from my searches online it looks to be a flutter specific dependency and not SPM or Cocoapods.

Anyways the draft PR with my changes is up and linked below :
Draft PR : #1155

You can review the changes and let me know if there’s something wrong, if you have the time I’d request you attempt to build it on your machine and see if you can reproduce the issue.

Note: Building with the SPM flag disabled works fine since it falls back to Cocoapods.

@navaronbracke
Copy link
Collaborator Author

I will take a look later this week. Thanks again for working on this!

@loic-sharma
Copy link

loic-sharma commented Aug 30, 2024

If we migrate to swift package manager, I’m encountering an error "Parse Issue (Xcode): Module 'image_picker_ios' not found” this seems to be a common issue with this module when we switch over to swift package manager.

Found an open issue in Git : flutter/flutter#152550

Hello @Xa69, you're the second person to report this problem. Unfortunately, I'm having difficulties reproducing this problem on my machine. Would you be able to share a sample project and instructions to reproduce this problem?

@Xa69
Copy link

Xa69 commented Aug 31, 2024

Hi @loic-sharma I’m not able to reproduce this as well as the build is getting stuck due to this other issue.
#953

I’m not sure what could be causing this as I’m using the latest Cocoapods however I will try to figure out how to reproduce this to help you debug further.

CC: @navaronbracke

@navaronbracke
Copy link
Collaborator Author

In #953 people seem to suggest it has to do with what cocapods version you are using?

@Xa69
Copy link

Xa69 commented Sep 1, 2024

@navaronbracke 1.15.2

@Xa69
Copy link

Xa69 commented Sep 1, 2024

Also @navaronbracke this build issue regarding the ‘MLKit’ is the same as our conversation which is ongoing here #1155.

Could you please try on your system and check if you can repro the ‘image_picker’ issue? I don’t remember any explicit steps for reproducing the issue.

Just running flutter build used to reproduce the ‘image_picker’ issue after enabling Swift package manager through the config command 'flutter config --enable-swift-package-manager’

You just need to checkout my branch 'users/nimish/1150-SPM-Support-Changes’ and try to build the example app.

@navaronbracke
Copy link
Collaborator Author

navaronbracke commented Sep 1, 2024

I can't reproduce this on an Intel Mac, on Flutter 3.24.1, using a fresh copy of your branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ios Platform iOS macos Platform macos
Projects
None yet
Development

No branches or pull requests

3 participants