aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 880 forks source link

Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.3 compiler #3033

Closed btreglia closed 3 years ago

btreglia commented 4 years ago

Describe the bug All swift files that "import AWSMobileClient" generate the error "Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.3 compiler"

My project is using the latest AWS iOS SDK (v 2.16.0). I am using many AWS v2.16 frameworks and AWSMobileClient is the only framework that is generating this error.

The problem I am experiencing is identical to this closed issue, except that issue was for a prior version of swift.

I was able to fix the issue by recompiling the AWSMobileClient framework from the source code with the setting BUILD_LIBRARIES_FOR_DISTRIBUTION = YES, and using this framework in my project. Not an ideal solution since this will require all users using Xcode 12 to recompile this framework, which is not a trivial exercise. The setting "BUILD_LIBRARIES_FOR_DISTRIBUTION = YES" must be set in the framework before it is compiled, not in the project that uses the framework as was suggested by AWS Support.

To Reproduce Steps to reproduce the behavior:

  1. Create a project in Xcode 12 (using the swift 5.3 compiler).
  2. Add AWSMobileClient framework
  3. Add "import AWSMobileClient" to one of the source files.
  4. Compile

Observed Behavior Build error: "Module compiled with Swift 5.2.4 cannot be imported by the Swift 5.3 compiler".

Expected Behavior Projects that Include the AWSMobileClient framework should compile without error, like the other AWS frameworks.

Areas of the SDK you are using (AWSMobileClient, Cognito, Pinpoint, IoT, etc)? AWSMobileClient AWSCore AWSCognitoIdentityProvider AWSCognitoIdentityProviderASF AWSAuthCore AWSDynamoDB AWSLambda AWSUserPoolSignIn

Screenshots

Screen+Shot+2020-09-17+at+9 10 00+AM

Environment(please complete the following information):

Device Information (please complete the following information): All devices and simulator

ruiguoamz commented 3 years ago

Hi, @btreglia Thanks for reaching out.

I can sometimes see the error. But in my laptop, when I do Cmd+Shift+K to clean the project and Cmd+B/Cmd+R to rebuild/rerun it, the error will just go away. Could you try it? Thanks

ray-liu-imeasureu commented 3 years ago

@ruiguoamz I have the exact same issue with @btreglia . Cleaning the build will not work. @btreglia has pointed out the fix. Just need to set BUILD_LIBRARIES_FOR_DISTRIBUTION = YES for the framework project setting and rebuild the framework.

btreglia commented 3 years ago

Hi, @btreglia Thanks for reaching out.

I can sometimes see the error. But in my laptop, when I do Cmd+Shift+K to clean the project and Cmd+B/Cmd+R to rebuild/rerun it, the error will just go away. Could you try it? Thanks

Hi @ruiguoamz,

I replaced the recompiled version of the AWSMobileClient framework that I created and replaced it with the original AWSMobileClient framework from the v2.16.0 zip and tried the clean/rebuild that you suggested and the error did not go away. I even deleted the DerivedDate folder but still received the same error.

Thanks.

palpatim commented 3 years ago

We'll investigate setting the BUILD_LIBRARIES_FOR_DISTRIBUTION flag to see if that fixes the issue--that didn't work previously because of a bug in Xcode.

EdGonzalez- commented 3 years ago

Hi @palpatim, any news on this?

palpatim commented 3 years ago

To the best of my ability to discern, the underlying Xcode issue has not yet been fixed. When I set the BUILD_LIBRARIES_FOR_DISTRIBUTION flag and attempt to import a binary framework built on Xcode 11.4.1/Swift 5.2 into a project, and build that project with Xcode 12/Swift 5.3, I still see the circular reference errors that are the hallmark of the known Swift issue, which has not yet been resolved:

There isn't a good workaround for this other than to ensure the framework binaries are built with the same version of Swift that your consuming project.

palpatim commented 3 years ago

I'm marking this issue with the "service" label to indicate that we believe it's related to an Apple/Swift bug, not a project issue. I'm also marking it "work in progress" because I want to dig into the project a bit more to see if I can find where this is coming from. When I create a dead simple project with a public type named the same as the module itself, and set the BUILD_LIBRARIES_FOR_DISTRIBUTION flag, I'm able to import a binary with no problems. Something about the complexity of the AWSMobileClient project is triggering the issue, so if we can find what that trigger is, we might gain some insight into a way to workaround the issue without renaming the module or the AWSMobileClient type itself (both of which would be significantly breaking changes).

rpotze commented 3 years ago

Same issue with SDK 2.19 and Xcode 12.2: Module compiled with Swift 5.3 cannot be imported by the Swift 5.3.1 compiler: [......]/Frameworks/AWSMobileClient.framework/Modules/AWSMobileClient.swiftmodule/arm64-apple-ios.swiftmodule

Same remedies tried as described above, to no avail. This is seriously impacting our ability to work with Cognito. For me, breaking changes would be preferable to non-working libraries.

palpatim commented 3 years ago

I have reproduced this with a barebones sample project and verified that the bug is not yet fixed as of Xcode 12.2.

Unfortunately, we can't find any good backwards-compatible options. At this point, we're exploring a couple of options:

We'll update this issue as we make progress.

jaelee1993 commented 3 years ago

Hey guys, was there any solution to this? Setting BUILD_LIBRARIES_FOR_DISTRIBUTION to YES did not work for me.

palpatim commented 3 years ago

@jaelee1993 The Swift bug is still unresolved. However, we're releasing support for XCFrameworks in 2.22.1, which will provide a new way for consuming these binary frameworks.

palpatim commented 3 years ago

As of 2.22.1, we distribute the AWSMobileClient binary as an XCFramework with the BUILD_LIBRARY_FOR_DISTRIBUTION flag enabled. Please see Carthage installation instructions or XCFramework installation instructions in the README for more info.

Do note that you will have to import a different module name; for backwards compatibility with CocoaPods users, we had to distribute the XCFramework binary under a different target. The usage at the call site remains the same:

YourAppCode.swift

import AWSMobileClientXCF // Note the new module name

// later, at the call site...
AWSMobileClient.default().initialize() { _ in print("AWSMobileClient initalized") }

Let us know if you have any questions. I will leave this issue open for a little bit to gather feedback and make sure we didn't miss any cases.

abildgaard commented 3 years ago

Added issue #3410 to provide more details


@palpatim very happy to see XCFramework release.

Sadly when we use the 2.22.1 XCFramework our app crashes with the following error message:

Fatal error: Use of unimplemented initializer 'init()' for class 'AWSMobileClientXCF.SignInUIOptions'

This happens when the mobileClient.showSignIn() call is made after we have initialized the AWSMobileClient:

import AWSMobileClientXCF
...
mobileClient = AWSMobileClient(configuration: configuration)
let hostedUIOptions = HostedUIOptions(scopes: ["openid"])
mobileClient.showSignIn(navigationController: navigationController, hostedUIOptions: hostedUIOptions) { (userState, error) in 
    // show success or failure 
}

As you see we don't use the AWSMobileClient.default() to initialize but use the AWSMobileClient(configuration: configuration) out of necessity.

This code works using the 2.22.0 frameworks (non XCFramework) compiled using Carthage.

Any suggestions ?

using: 
- Xcode 12.4 / iOS 14.4 
- AWS SDK iOS 2.22.1 (XCFrameworks)
- AWSAuthCore.xcframework
- AWSCognitoIdentityProvider.xcframework
- AWSCognitoIdentityProviderASF.xcframework
- AWSCore.xcframework
- AWSMobileClientXCF.xcframework
palpatim commented 3 years ago

https://github.com/aws-amplify/aws-sdk-ios/issues/3410 closed by https://github.com/aws-amplify/aws-sdk-ios/issues/3033.

I'm optimistically closing this issue since we haven't heard any other issues on this. Please feel free to open a new issue with details if you have problems with the XCFrameworks distributions.