Skip to content

fix(iOS): use literal target name in Package.swift instead of a let variable - #409

Merged
AlexV525 merged 2 commits into
fluttercandies:mainfrom
BenBaggley:fix/ios-spm-package-swift-literal-target-name
Oct 18, 2026
Merged

AlexV525 merged 2 commits into
fluttercandies:mainfrom
BenBaggley:fix/ios-spm-package-swift-literal-target-name

Conversation

@BenBaggley

@BenBaggley BenBaggley commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

flutter build swift-package --platform ios fails on any app depending on flutter_image_compress with:

Failed to add FlutterFramework as a target dependency. error: unable to find target named 'flutter_image_compress_common' in package

Root cause

Flutter's tooling injects the FlutterFramework dependency into each plugin's Package.swift by running swift package add-target-dependency. That SwiftPM subcommand edits the manifest via syntactic source parsing, not evaluation — it can't resolve a target/product name expressed through a let packageName = "..." variable, even though swift package dump-package (which evaluates the manifest) resolves it fine.

Confirmed in isolation, independent of this plugin: a minimal Package.swift using .target(name: packageName) fails the same add-target-dependency call with the same error; switching to a literal .target(name: "Foo") succeeds.

Fix

Replace the packageName variable with literal strings.

Test plan

  • swift package dump-package still parses the manifest correctly.
  • swift package add-target-dependency FlutterFramework flutter_image_compress_common now succeeds (previously failed).
  • fvm flutter build swift-package --platform ios proceeds past this plugin.

🤖 Generated with Claude Code

…ariable

Flutter's `flutter build swift-package` invokes `swift package
add-target-dependency` to inject the FlutterFramework dependency into
plugin manifests. That SwiftPM command edits Package.swift via
syntactic source parsing rather than manifest evaluation, so it cannot
resolve a target/product name expressed through a `let packageName`
variable, failing with "unable to find target named
'flutter_image_compress_common' in package" even though the target
exists. Using the literal string lets SwiftPM locate and edit the
target correctly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@BenBaggley
BenBaggley requested a review from AlexV525 September 11, 2026 08:12

@CaiJingLong CaiJingLong left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8d2cf43. The literal target name addresses SwiftPM’s syntax-based target lookup, and the remaining substitutions preserve the package/product names and header search path. The earlier request to remove packageName has been addressed. No blocking findings.

All nine checks passed, including the iOS SwiftPM build and integration tests (18 passed, with two Android-only tests skipped). I did not rerun Swift/Flutter locally; the existing CI does not exercise the exact flutter build swift-package command.

@AlexV525
AlexV525 merged commit 5bc26a3 into fluttercandies:main Oct 18, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants