aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
447 stars 193 forks source link

SPM dependency resolution failure using amplify-swift 2.6.0 and aws-mobile-appsync-sdk-ios 3.6.2 #2813

Closed martinrist closed 1 year ago

martinrist commented 1 year ago

Describe the bug

We are currently migrating to v2.x of the amplify-swift library in order to use some new authentication features that are only available in Amplify 2.x.

However, our current AppSync schema and model generation process requires us to use aws-mobile-appsync-sdk-ios, since the Amplify CLI's amplify codegen command generates models that import AWSAppSync and uses the Apollo GraphQL-style API (e.g. GraphQLMapConvertible, GraphQLMap etc).

However, when I attempt to create a package dependency on amplify-swift v2.6.0 alongside aws-mobile-appsync-sdk-ios v.3.6.2, I get a large number of errors during package resolution. These are all of the form:

multiple products named 'AWSPolly' in: 'aws-sdk-ios-spm', 'aws-sdk-swift'

and

multiple targets named 'AWSPolly' in: 'aws-sdk-ios-spm', 'aws-sdk-swift'; consider using the `moduleAliases` parameter in manifest to provide unique names

There are a total of 33 such pairs of messages, with each of a number of AWS libraries appearing twice - once with each message.

Steps To Reproduce

Steps to reproduce the behavior:
1. Create a new blank Xcode project using the 'App' template
2. Add a package dependency to https://github.com/aws-amplify/amplify-swift, using 'exact version' 2.6.0
3. Observe that package resolution completes successfully
4. Add a package dependency to https://github.com/awslabs/aws-mobile-appsync-sdk-ios, using 'exact version' 3.6.2
5. Observe that package resolution fails with the errors described above

*Note:* Reversing steps 2 and 4 (adding the dependencies in the opposite order) has no effect - the same dependency resolution issues are seen.

Expected behavior

Both versions of the libraries should be able to coexist as separate dependencies. It should be possible to continue to use aws-mobile-appsync-sdk-ios 3.6.2 and amplify-swift 2.6.0 alongside each other.

Amplify Framework Version

2.6.0

Amplify Categories

API

Dependency manager

Swift PM

Swift version

5.7

CLI version

10.7.3

Xcode version

14.2 (14C18)

Relevant log output

N/A

Is this a regression?

No

Regression additional context

No response

Device

N/A - package resolution / build issue

iOS Version

N/A

Specific to simulators

No

Additional context

Also posted on aws-mobile-appsync-sdk-ios issues at https://github.com/awslabs/aws-mobile-appsync-sdk-ios/issues/566

martinrist commented 1 year ago

Initial investigation that we've done so far into the cause of the dependency resolution failure:

amplify-swift 2.6.0 depends on aws-sdk-swift 0.6.1, which includes a number of products / targets.

aws-mobile-appsync-sdk-ios 3.6.2 depends on aws-sdk-ios-spm 2.30.1 ... 2.31.0. At time of writing, that's currently resolving to 2.30.4, which looks like it's programatically creating products and targets which looks like it's based on a map that overlaps with those exposed by amplify-swift.

msk-psp commented 1 year ago

In my case, I was trying to upgrade version from 1.x something, the same error came out when 2.6.0 version of sdk has installed.

And I realized that I have aws-sdk-ios-spm package dependency too, when I removed the dependency it worked well

martinrist commented 1 year ago

If I have amplify-swift 2.6.0 and aws-sdk-ios-spm 2.30.4 added as top-level package dependencies, then I'm seeing the same 'duplicate product' / 'duplicate target' failures as @msk-psp . This seems to confirm that's the root cause.

Unfortunately, in our case, aws-sdk-ios-spm is a transitive dependency of aws-mobile-appsync-sdk-ios, so we're not able to remove the aws-sdk-ios-spm dependency without getting rid of all of the features of aws-mobile-appsync-sdk-ios.

Our long-term plan is to migrate to using the AppSync features in Amplify v2.x. However, that's a big migration path, as the AppSync client-side API has changed significantly between aws-mobile-appsync-sdk-ios and amplify-swift 2.6.0. We don't have time to do that migration as part of moving to Amplify v2.x (which is required for a different reason), so we're trying to explore whether it's possible to use a combination.

royjit commented 1 year ago

Unfortunately Amplify v2 is not compatible with aws-sdk-ios. The root cause being the underlying low level SDK are different in Amplify v2, it uses aws-sdk-swift instead of aws-sdk-ios. This cause naming conflict if you use the library along with aws-sdk-ios.

If you would like to use Amplify with aws-sdk-ios, one option is to use the v1 version of Amplify, which depend on the aws-mobile-appsync-sdk-ios.

martinrist commented 1 year ago

@royjit - thanks for the confirmation. I was expecting that to be the result, but good to hear that we've not missed a subtle workaround to resolve the issue.

Unfortunately we have no choice but to use Amplify v2, as we need some of the features that aren't in v1. So we'll have to focus on the full migration.

I'm happy to mark this issue as closed, now that it's confirmed there's no resolution.

mansidaksgh commented 6 months ago

Wait so do just use exact version of 2.72.2? Kinda confused on how to make this work.