Skip to content
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

Swift compiler errors #7

Closed
FrankFundel opened this issue Jan 9, 2021 · 10 comments
Closed

Swift compiler errors #7

FrankFundel opened this issue Jan 9, 2021 · 10 comments

Comments

@FrankFundel
Copy link

I get these strange errors after installing the package.

Does anyone know what the issue is? I could install it perfectly on another newer project.

Kind regards,
Frank

@dominicstop
Copy link
Owner

dominicstop commented Jan 9, 2021

This is the first time I'm encountering this error 😅

Could you post what RN version you're using, your target iOS version, and your Xcode version? I'll try making a fresh project to reproduce.
This a long shot, but maybe it's related to 1.1.2 Xcode Build Error (Undefined symbol)?

In the meantime, I'm gonna do some debugging... 😔


Edit: I'm trying out the example app, and everything seems to work just fine. I'm going to try it on a fresh RN project next.

  • I'm using Xcode 12.3, and RN ver. 0.63.4
  • Deploying on iOS 10, and running it on the iOS 14.3 Simulator
  • Clean build + Cleared derivedData

@FrankFundel
Copy link
Author

I'm on:
react-native-cli: 2.0.1
react-native: 0.61.5
and XCode 11.5

Clean build + Cleared derivedData.
Maybe it has something to do with that: https://stackoverflow.com/questions/40040570/swift-compiler-error-on-pods
I will try out tomorrow thank you for your help.

@dominicstop
Copy link
Owner

Hello, forgot to post this before I fell asleep last night 😴

I created a fresh RN project (the latest ver. is 0.63.4) to try and reproduce the error:

  1. Ran: npx react-native init contextMenuTest6v0634
  2. Made sure that it builds/runs
  3. Installed the library: yarn add react-native-ios-context-menu and cd ios && pod install
  4. Tried to build the app and encountered this error:

Screen Shot 2021-01-10 at 1 37 52 AM

  1. Followed 1.1.2 Xcode Build Error (Undefined symbol), added an empty swift file, did a clean build, and run the app

Screen Shot 2021-01-10 at 7 54 42 AM

  1. Couldn't reproduce the error 😔

Gonna try again with RN 0.61.5 later...

@dominicstop
Copy link
Owner

So maybe the problem is with Xcode 11.5 and RN 0.63.4 ? I don't have enough space to install another version of Xcode haha, so I'm going to use github actions:

  1. Ran: npx react-native init contextMenuTest7v0615 --version 0.61.5

  2. Made sure that it runs/builds, and then published the repo to github

  3. Made a github action that builds the app using Xcode 11.5

  4. Did a test run and triggered the github action to make sure it works

  5. Installed react-native-ios-context-menu on the test project (commit link):

    • Installed the library: yarn add react-native-ios-context-menu
    • Bumped the test project's deployment target from iOS 9.0 -> iOS 10.0 to fix the pod error: [!] CocoaPods could not find compatible versions for pod "react-native-ios-context-menu": [...] but they required a higher minimum deployment.
    • Followed 1.1.1 Xcode Build Error (Swift) to fix the pod error: [!] Unable to determine Swift version for the following pods: "react-native-ios-context-menu" does not specify a Swift version and none of the targets ("contextMenuTest7v0615") integrating it have the "SWIFT_VERSION" attribute set. [...]
    • Followed 1.1.3 Cocoapods Static Libraries Error to fix pod error: The Swift pod "react-native-ios-context-menu" depends upon "React-Core", which does not define modules. [...]
    • Ran pod install
  6. Tried building the app locally on Xcode and encountered no errors so far:

image

  1. Triggered the github build action to test if it still builds on Xcode 11.5

@dominicstop
Copy link
Owner

dominicstop commented Jan 10, 2021

I finally was able to reproduce your error 😅

The github action failed to build the project with the following error:

image

image

image

Link to full logs


The next step is to figure out what went wrong 😅

  • The problem is with Xcode 11.5 and react-native: 0.61.5 (and I think that it has something to do with the Library Search Path build setting in the react-native: 0.61.5 template)
  • Here is a related issue comment I've found referenced in 1.1.2 Xcode Build Error (Undefined symbol)

Quote:

I also had this issue and asked about it on the Swift forums. The cause is trying to link against an older Swift runtime while targeting a newer version of the OS.

You should be able to just remove those LIBRARY_SEARCH_PATH entries entirely (or just leave $(inherited)) and that will fix the problem. This is a bug in the ReactNative template for iOS.

As mentioned in the above Swift forums thread:

You shouldn't need to add the toolchain library paths to LIBRARY_SEARCH_PATHS yourself, because Xcode will automatically include those libraries if your minimum deployment target is old enough to need them.

@dominicstop
Copy link
Owner

dominicstop commented Jan 10, 2021

I've found the solution, but you aren't going to like it 😔
(skip to the end if you don't want to see the explanation haha)

  • I finally was able to build the test app using Xcode 11.5 using this GH action (here's a link to the build output).
  • In the build errors, I have noticed that Xcode was complaining about the iOS-14 specific API's of UIMenu (so at the very least, Xcode was aware that UIKit.UIMenu exists, just not the iOS 14 version of it).
  • That's why most of the errors are from RCTContextMenuButton because it was using the context menu API's for UIButton that were introduced in iOS 14.

  • It turns out that it was problem with the Xcode Swift toolchain. In the Build App w/ Swift 5.3 GH action, it's using the swift 5.3 toolchain for Xcode 12.
  • Swift 5.3 is important because that's the version of swift that was released with iOS 14 (this is also the reason why the same app builds on Xcode 12, but fails to build on Xcode 11. Xcode 12 is using a newer version of swift).
  • In other words, certain framework features (such as UIKit.UIMenu) are tied to a the version of swift that Xcode is using (any mismatch causes the build to fail, presumably because the newer API's aren't declared in the headers).

So the steps to fix this are the same as before:

  1. Ran: npx react-native init contextMenuTest7v0615 --version 0.61.5

  2. Made sure that it runs/builds, and then published the repo to github

  3. Made a github action that builds the app using Xcode 11.5

  4. Did a test run and triggered the github action to make sure it works

  5. Installed react-native-ios-context-menu on the test project (commit link):

    • Installed the library: yarn add react-native-ios-context-menu
    • Bumped the test project's deployment target from iOS 9.0 -> iOS 10.0 to fix the pod error: [!] CocoaPods could not find compatible versions for pod "react-native-ios-context-menu": [...] but they required a higher minimum deployment.
    • Followed 1.1.1 Xcode Build Error (Swift) to fix the pod error: [!] Unable to determine Swift version for the following pods: "react-native-ios-context-menu" does not specify a Swift version and none of the targets ("contextMenuTest7v0615") integrating it have the "SWIFT_VERSION" attribute set. [...]
    • Followed 1.1.3 Cocoapods Static Libraries Error to fix pod error: The Swift pod "react-native-ios-context-menu" depends upon "React-Core", which does not define modules. [...]
    • Ran pod install
  6. Tried building the app locally on Xcode and encountered no errors so far:

But if you are using Xcode 11, you have to change the swift version that Xcode is using to at least: Swift 5.3

  • Based on this article, it's quite a lengthy process...
  • You can either A: upgrade to Xcode 12, B: change your Xcode's toolchain that uses swift 5.3, or C: just use a different library (honestly, this is not worth all the hassle 😔)

I'm sorry I could't find a better solution, but this is something that is out of my abilities. The problem is with the version of Xcode you are using (and the fact that this library is using iOS 14 specific API's... ☹️)


Honestly, this library is a mess to install because of the problems regarding Xcode/Swift/Cocoapods.
I'm going to take a nap haha hope you find a solution that you are happy with, best of luck! ✨

@FrankFundel
Copy link
Author

FrankFundel commented Jan 10, 2021

Thank you for your awesome work so far 😀 Your solution is a bit confusing to me because on another project it works using the same XCode version. Maybe I can specify in my project which version of Swift to use? (maybe the project uses an older swift version because I have another pod in it which also uses swift)

UPDATE: I tried changing Swift Language Version to 5.0 like in my other project, but as you said I need at least 5.3
Then I downgraded your package to 0.1.2 (the version I used in my other app) and it worked with 5.0
I installed Swift 5.3 Toolchain using https://rizwan95.medium.com/installing-swift-5-toolchain-in-xcode-24fcc62b33ba
Updated react-native-ios-context-menu
I don't know if it would work because now I can only compile on simulator and not on real device :(
"the swift standard library from the toolchain cannot be used on devices" (which many people have but no solution)
If I run on a simulator, I get other errors:
Screenshot_2
Thus I think switching toolchain is not a good solution, I would need to update to the new macOS and XCode. Is it really crucial for you to use Swift 5.3? If you can you sould try to use the lowest versions possible, so more people can use it :D I will for now just stick with react-native-ios-context-menu v0.1.2

@dominicstop dominicstop reopened this Jan 10, 2021
@dominicstop
Copy link
Owner

I'm sorry, this library is a mess haha 😔 (I'll take a look at this later, and do some more tests)


At the mean time, what did you do, and what errors did you encounter? I don't mind if you just paste the entire error/logs + build settings haha (it'll help with debugging). I'll follow along step by step and I'll try to reproduce the errors 😅


This would be a lot easier it i could install Xcode 11 (but I only have 4GB's of space left 🤣)

@FrankFundel
Copy link
Author

Nooo this library is really good. I described what I did in the comment above, I have not logs :/
When was the last version that used Swift 5.0 instead of Swift 5.3? I need ContextButton :(

@dominicstop
Copy link
Owner

dominicstop commented Jan 11, 2021

Here's what I've found after some testing haha

  • For Xcode 11.5 it uses: Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
  • For Xcode 12.3 it uses: Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)

I'm a noob at Xcode but I can't figure how to make this work... I'm afraid that I'll end up breaking something if i mess with the build settings haha

It looks like the simplest solution is to just upgrade to Xcode 12.3. I didn't want to update, but I've been using it for a while and it's pretty good!


In the meantime, I'm going to try and set the podspec for this library to: s.swift_version = '5.3' and try to install it using Xcode 11.5

Edit: it didn't work haha


Edit: I've come to the conclusion that certain iOS features and API's are tied to Xcode releases. If you want to use the newer API's, then you need to upgrade your version of Xcode. This means that it's okay to stay on older Xcode versions as long as you aren't using any of the newer API's. This is why version 0.1.2 of this library works on Xcode 11 (I haven't used or reference any of the iOS 14 API's for UIContextMenu yet at that point).

Unfortunately, since the later versions of this library are referencing iOS 14 specific API's (which are optional to use), you need to use the version of Xcode that was released alongside with iOS 14 (which is Xcode 12) to use this.


So in summary, you just really need to upgrade your version of Xcode or stay on an older version of this library haha 😅

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

No branches or pull requests

2 participants