Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[SwiftPM] Plugin not found right after adding #162399

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

Open
Tracked by #126005
vashworth opened this issue Jan 29, 2025 · 3 comments · Fixed by #163275
Open
Tracked by #126005

[SwiftPM] Plugin not found right after adding #162399

vashworth opened this issue Jan 29, 2025 · 3 comments · Fixed by #163275
Assignees
Labels
P1 High-priority issues at the top of the work list platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@vashworth
Copy link
Contributor

Steps to reproduce

Using Flutter 3.27.1, Xcode 16.2, iOS Simulator 18.2:

  1. Create a SwiftPM plugin:

    flutter config --enable-swift-package-manager
    flutter create --template=plugin --platforms=ios plugin_a
    
  2. Create a SwiftPM app:

    flutter config --enable-swift-package-manager
    flutter create my_app
    cd my_app
    flutter build ios --config-only
    
  3. Open project in Xcode

    1. Open the app's ios/Runner.xcworkspace using Xcode
  4. Modify my_app/pubspec.yaml to depend on the plugin:

      dependencies:
    +   plugin_a:
    +     path: ../plugin_a
  5. Start iOS simulator 18.2

  6. Run the app:

flutter run

Expected results

I expect plugin_a to be found. I suspect this is a caching issue that's cause by having the project open in Xcode while also running from the command line, but we should look into it more.

Actual results

           ComputeTargetDependencyGraph
           note: Building targets in dependency order
           note: Target dependency graph (3 targets)
               Target 'Runner' in project 'Runner'
                   ➜ Explicit dependency on target 'FlutterGeneratedPluginSwiftPackage' in project 'FlutterGeneratedPluginSwiftPackage'
               Target 'FlutterGeneratedPluginSwiftPackage' in project 'FlutterGeneratedPluginSwiftPackage'
                   ➜ Explicit dependency on target 'FlutterGeneratedPluginSwiftPackage' in project 'FlutterGeneratedPluginSwiftPackage'
               Target 'FlutterGeneratedPluginSwiftPackage' in project 'FlutterGeneratedPluginSwiftPackage' (no dependencies)

...

GeneratedPluginRegistrant.m:12:9: error: Module 'plugin_a' not found (in target 'Runner' from project 'Runner')

Code sample

Code sample
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]
@vashworth vashworth added P2 Important issues not at the top of the work list team-ios Owned by iOS platform team labels Jan 29, 2025
@vashworth vashworth changed the title [SwiftPM] [SwiftPM] Plugin not found right after adding Jan 29, 2025
@vashworth vashworth added platform-ios iOS applications specifically triaged-ios Triaged by iOS platform team labels Jan 29, 2025
@matanlurey
Copy link
Contributor

I wrote on #163272, but I believe this is why:

https://github.com/flutter/flutter/blob/main/packages/flutter_tools/lib/src/macos/cocoapod_utils.dart#L51

This was written under the assumption the .flutter-plugins file was not used by the iOS tooling, but that seems not to be true. iOS tooling has multiple passes where it generates plugin related files (see #157391), so it probably eventually works, but the first time we omit this file, so it does not (that's my guess at least).

@matanlurey
Copy link
Contributor

Ok, it's not exactly used, but it does determine whether some symlink step is created or not:

if (changed || legacyChanged || forceCocoaPodsOnly) {
createPluginSymlinks(project, force: true);
if (iosPlatform) {
globals.cocoaPods?.invalidatePodInstallOutput(project.ios);
}
if (macOSPlatform) {
globals.cocoaPods?.invalidatePodInstallOutput(project.macos);
}
}

@matanlurey matanlurey self-assigned this Feb 14, 2025
github-merge-queue bot pushed a commit that referenced this issue Feb 18, 2025
…ntent changes. (#163275)

Closes #162399.
Closes #163272.

`refreshPluginsList` is commonly called in iOS/macOS apps, more times
than you expect (and load bearing);
#157391.

With `--explicit-package-dependencies`, we no longer write (or compare)
the output of `.flutter-plugins`. The iOS/macOS workflows required `pod
install` output to be invalidated when plugins when change, but the
logic that was being used to see if plugins changed _only_ worked for
the `.flutter-plugins` file format.

In the original code:

```txt
# oldPluginsFileStringContent
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"integration_test","path":"/Users/matanl/Developer/flutter/packages/integration_test/","native_build":true,"dependencies":[],"dev_dependency":false},{"name":"ios_objc_cocoapods_plugin","path":"/var/folders/qw/qw_3qd1x4kz5w975jhdq4k58007b7h/T/swift_package_manager_enabled.XrEWXS/ios_objc_cocoapods_plugin/","native_build":true,"dependencies":[],"dev_dependency":false}],"android":[{"name":"integration_test","path":"/Users/matanl/Developer/flutter/packages/integration_test/","native_build":true,"dependencies":[],"dev_dependency":false}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"integration_test","dependencies":[]},{"name":"ios_objc_cocoapods_plugin","dependencies":[]}],"date_created":"2025-02-13 17:01:11.023097","version":"3.30.0-1.0.pre.163","swift_package_manager_enabled":{"ios":true,"macos":false}}

# pluginsMap
{ios: [{name: integration_test, path: /Users/matanl/Developer/flutter/packages/integration_test/, native_build: true, dependencies: [], dev_dependency: false}, {name: ios_objc_cocoapods_plugin, path: /var/folders/qw/qw_3qd1x4kz5w975jhdq4k58007b7h/T/swift_package_manager_enabled.XrEWXS/ios_objc_cocoapods_plugin/, native_build: true, dependencies: [], dev_dependency: false}], android: [{name: integration_test, path: /Users/matanl/Developer/flutter/packages/integration_test/, native_build: true, dependencies: [], dev_dependency: false}], macos: [], linux: [], windows: [], web: []}
```

As you can see, `pluginsChanged =
oldPluginsFileStringContent.contains(pluginsMap.toString());` was
_always_ `false`, but we never knew because we'd always just fall back
to using the `.flutter-plugins` content comparison (which always
worked).

I added a test as well.

This also appears to fix
#162399.

/cc @jmagman @jonahwilliams
Copy link

github-actions bot commented Mar 4, 2025

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 4, 2025
@vashworth vashworth reopened this May 2, 2025
@vashworth vashworth assigned vashworth and unassigned matanlurey May 2, 2025
@vashworth vashworth added P1 High-priority issues at the top of the work list and removed P2 Important issues not at the top of the work list labels May 2, 2025
@flutter-triage-bot flutter-triage-bot bot unlocked this conversation May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High-priority issues at the top of the work list platform-ios iOS applications specifically team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants