exponea / exponea-react-native-sdk

MIT License
8 stars 13 forks source link

Can't run on Xcode 12.4 iOS 14.4 and Swift Version 5.3.2 #12

Closed nikolovnikos closed 3 years ago

nikolovnikos commented 3 years ago

Hi, I installed "react-native-exponea-sdk": "^0.5.0" on react-native: 0.61.5 project but when run on Xcode 12.4 I see some Swift Compiler Errors

  1. Cannot convert value of type 'T??' to specified type 'NSDictionary?' and Generic parameter 'T' could not be inferred - in parsePushNotificationTracking func in ConfigurationParser.swift if let iosDictionary: NSDictionary = try? dictionary.getOptionalSafely(property: "ios") { appGroup = try iosDictionary.getOptionalSafely(property: "appGroup") ?? appGroup } also here if let iosDictionary: NSDictionary = try? dictionary.getOptionalSafely(property: "ios") { requirePushAuthorization = try iosDictionary.getOptionalSafely(property: "requirePushAuthorization") ?? true }

  2. _'ExponeaAppDelegate' has different definitions in different modules; first difference is definition in module 'react_native_exponea_sdk' found super class with type 'UIResponder'_ - in ExponeaAppDelegate.h - fixed by adding libExponeaSDK.a in Link Binary manually

React-native info:

System: OS: macOS 11.1 CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz Memory: 72.05 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 12.16.2 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.4 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 4.1 AI-201.8743.12.41.6953283 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: @react-native-community/cli: ^3.0.4 => 3.2.1 react: 16.9.0 => 16.9.0 react-native: 0.61.5 => 0.61.5

nikolovnikos commented 3 years ago

I just added libExponeaSDK.a in Link Binary manually. This fixed the second error 'ExponeaAppDelegate' has different definitions...'

Just to Notice, first I run pod install to auto-link.

nikolovnikos commented 3 years ago

also to mention the current swift version: 5.3.2

Igi4 commented 3 years ago

Hi @nikolovnikos,

thanks for the report! Sorry it took until now but this has been quite peculiar issue. I believe this could help you.

You actually managed to find 2 separate issues so let's go step by step.

  1. 'ExponeaAppDelegate' has different definitions in different modules; first difference is definition in module 'react_native_exponea_sdk' found super class with type 'UIResponder' - in ExponeaAppDelegate.h

This is the easier one. Based on our testing, it happens only with completely empty Derived Data folder (the folder where iOS stores all build-related files, .app folders, compiled files, etc.). After it fails it should be sufficient to just build the iOS project second time and the build succeeds (we tested it both by directly building in Xcode and also via yarn run ios in terminal). This is happening due to the same name of the app delegate class in both Exponea React Native SDK and the underlying Exponea iOS SDKs. We will change the name in future release of the Exponea React Native SDK. For now, the workaround is to just rebuild the iOS project second time if this error shows up until then.

  1. Cannot convert value of type 'T??' to specified type 'NSDictionary?' and Generic parameter 'T' could not be inferred

This one was trickier. I believe this is just one of many issues that occurred when building the project. First of all, we were able to reproduce it on React Native 0.61.5 but it didn't occur in freshly created empty project based on newer React Native 0.63.2. We noticed in the build log the following warning:

ld: warning: Could not find or use auto-linked library 'swiftFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCompatibility51'
ld: warning: Could not find or use auto-linked library 'swiftMetal'
ld: warning: Could not find or use auto-linked library 'swiftDarwin'
ld: warning: Could not find or use auto-linked library 'swiftCloudKit'
ld: warning: Could not find or use auto-linked library 'swiftUIKit'
ld: warning: Could not find or use auto-linked library 'swiftCoreData'
ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCompatibility50'
ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
ld: warning: Could not find or use auto-linked library 'swiftCore'
ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
ld: warning: Could not find or use auto-linked library 'swiftDispatch'
ld: warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
ld: warning: Could not find or use auto-linked library 'swiftCompatibilityDynamicReplacements'
ld: warning: Could not find or use auto-linked library 'swiftCoreLocation'

It seems that Swift standard libraries are missing and that's why the Exponea SDK's Swift files produce various errors. Solution here is to add an empty Swift file into <project root dir>/ios, e.g. File.swift with empty content:

import Foundation

This needs to be done in Xcode (File -> New -> File -> Swift File). When Xcode asks you if you want to create bridging headers, it's not necessary to do so.

Clean the project, rebuild it and it should succeed. Please let me know if this worked.

nikolovnikos commented 3 years ago

Hi,

Thank you for the answer.

Just to notice: I don't see any warnings only Swift Compiler Errors in Issue Navigator in Xcode

Igi4 commented 3 years ago

Hi,

Could you please try deleting the whole content of Derived Data folder for your app (not just cleaning the project) and then rebuild via Xcode?

If that doesn't help, could you please post here the whole output from the building process (as a file, preferrably)?

Thanks

nikolovnikos commented 3 years ago

Hi,

I deleted the Derived Data folder for my project and then rebuild it. Same errors. Here is a doc with exported Issue Navigator from Xcode: https://docs.google.com/document/d/18HrhnSc3AMC5rYkpF-HTgfm1GpCuCpO7UeWq1PAcTn4/edit?usp=sharing

Igi4 commented 3 years ago

This looks like a problem with the nested optional returned by try? dictionary.getOptionalSafely(property: "ios").

Unfortunately, I'm not able to reproduce this (RN 0.61.5, Swift 5.3.2, Xcode 12.4), clean project with installed SDK compiles correctly.

Could you please edit ConfigurationParser.swift in Development Pods and change try? to try on lines 68 and 81?

nikolovnikos commented 3 years ago

This works. Now the project is building with no swift errors.

Igi4 commented 3 years ago

Glad to hear that. Do you think you could try it on a clean project?

npx react-native init AwesomeProject --version 0.61.5 cd AwesomeProject yarn add react-native-exponea-sdk cd ios pod install

Then try to build it. First time it should fail on the AppDelegate error and you may also need to add the empty swift file as I proposed earlier. After these steps the project compiles fine on my machine. Could you please verify this?

Igi4 commented 3 years ago

@nikolovnikos What build system do you use? (In Xcode it's File -> Workspace Settings)

I used the new build system:

Screenshot 2021-02-11 at 12 01 16
nikolovnikos commented 3 years ago

@nikolovnikos What build system do you use? (In Xcode it's File -> Workspace Settings)

I used the new build system:

Screenshot 2021-02-11 at 12 01 16

Legacy Build System, because of other SDK

nikolovnikos commented 3 years ago

Glad to hear that. Do you think you could try it on a clean project?

npx react-native init AwesomeProject --version 0.61.5 cd AwesomeProject yarn add react-native-exponea-sdk cd ios pod install

Then try to build it. First time it should fail on the AppDelegate error and you may also need to add the empty swift file as I proposed earlier. After these steps the project compiles fine on my machine. Could you please verify this?

will try it

Igi4 commented 3 years ago

I was able to build it also after switching to legacy build system, so that's not it.

nikolovnikos commented 3 years ago

So I created a new RN project with 0.61.5. Where I have to add not only platform :ios, '10.3' but also ENV['SWIFT_VERSION'] = '5' at the top of the pod file. This fix errors in ConfigurationParser.swift file. No need for manual editing the code. I've implemented this in my production project and now is working with no manual editing of the code

Igi4 commented 3 years ago

Thanks, we'll update the documentation to mention this.

I added SWIFT_VERSION = 5 to User Defined section in Xcode as without it, the pod didn't event want to install.

Thanks for your help!

Igi4 commented 3 years ago

@nikolovnikos One question. In your project, did you have the SWIFT_VERSION value set to a different value, or you didn't have it there at all?

nikolovnikos commented 3 years ago

My SWIFT_VERSION in Pods -> Build Settings is 5.0

nikolovnikos commented 3 years ago

I can confirm it - Without ENV['SWIFT_VERSION'] = '5' you can't install pods on RN 0.61.5. With this in the Podfile, everything is working with no errors - building and running

Igi4 commented 3 years ago

@nikolovnikos thank you.

We noticed one thing in the log file you sent earlier:

Conversion to Swift 5 is available

That indicates that you might have been using an older version of Swift which would explain the compilation errors and why we weren't able to reproduce this on a clean project.

nikolovnikos commented 3 years ago

Yes, I migrated to SWIFT 5.0 now all good.