meteor / cordova-plugin-meteor-webapp

Cordova plugin that serves a Meteor web app through a local server and implements hot code push
MIT License
66 stars 74 forks source link

iOS build fails on Xcode 10.2 / Swift 3 no longer supported #76

Closed alanning closed 5 years ago

alanning commented 5 years ago

Xcode 10.2 apparently no longer supports Swift 3.

Reproduction:

$ meteor create --full iosTest
$ cd iosTest
$ meteor add-platform ios
$ meteor run ios-device

Opens Xcode 10.2 and a dialog box appears with the following error message:

Unsupported Swift Version

The target “iosTest” contains source code developed with Swift 3.x. This version of Xcode does not support building or migrating Swift 3.x targets.

Use Xcode 10.1 to migrate the code to Swift 4.

Changing the SWIFT_VERSION to 4.0 and attempting to build produces the following errors:

/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/AssetBundle.swift:13:65: 'rangeAt' has been renamed to 'range(at:)'
/Foundation.NSTextCheckingResult:25:15: 'rangeAt' was obsoleted in Swift 4
/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/Utility.swift:16:56: 'rangeAt' has been renamed to 'range(at:)'
/Foundation.NSTextCheckingResult:25:15: 'rangeAt' was obsoleted in Swift 4
/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/Utility.swift:30:51: 'rangeAt' has been renamed to 'range(at:)'
/Foundation.NSTextCheckingResult:25:15: 'rangeAt' was obsoleted in Swift 4
/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/AssetBundleDownloader.swift:81:60: Argument of '#selector' refers to instance method 'applicationWillEnterForeground()' that is not exposed to Objective-C
/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/AssetBundleDownloader.swift:211:8: Add '@objc' to expose this instance method to Objective-C
/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/WebAppLocalServer.swift:116:60: Argument of '#selector' refers to instance method 'pageDidLoad()' that is not exposed to Objective-C
/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/WebAppLocalServer.swift:212:8: Add '@objc' to expose this instance method to Objective-C
/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/WebAppLocalServer.swift:118:60: Argument of '#selector' refers to instance method 'applicationDidEnterBackground()' that is not exposed to Objective-C
/Users/alanning/tmp/iosTest/.meteor/local/cordova-build/platforms/ios/iosTest/Plugins/cordova-plugin-meteor-webapp/WebAppLocalServer.swift:215:8: Add '@objc' to expose this instance method to Objective-C
alanning commented 5 years ago

I'd like to work on updating this to Swift 5 and would appreciate some guidance.

Attempting to run the existing test suite results in:

$ yarn test
yarn run v1.13.0
$ ios-sim start --devicetypeid=iPhone-X
No available runtimes could be found for "iPhone X".

I would guess I need to install the cordova platform with the latest simulators (probably cordova ios@5) but I'm getting stuck on how to do that for this project.

'cordova' is included as a devDependency but $ npx cordova platforms gives this message:

"Current working directory is not a Cordova-based project."

Any tips on getting my environment set up to run these tests?

Caveat: I'm leery of doing something like installing cordova platform 5 globally since I need to continue to develop an existing Meteor app and don't want to mess that up.

rj-david commented 5 years ago

@benjamn, I know 1.8.1 is now in code freeze. And not sure about plans for 1.9.

But seems like this is a critical issue. Can you give guidance on how we can help?

alanning commented 5 years ago

Thanks for the prompt, @rj-david. I think this is not necessarily a critical issue since there exists a fairly simple workaround of reverting back to Xcode 10.1.

But now that Apple is auto-updating everyone to Xcode 10.2, it does make it a fairly widespread and visible pain-point for anyone using Meteor Cordova.

The referenced issue on Meteor proper (https://github.com/meteor/meteor/issues/10511) is probably a good place to track the overall work needed to support Xcode 10.2 since we also need to support the latest version of the underlying cordova-ios dependency and I would guess that would require further updates of the other cordova plugins that Meteor uses.

rj-david commented 5 years ago

Good point about being able to still use xcode 10.1.

Hopefully, Apple won't change the minimum requirements of submission to the app store soon. It is now pegged at iOS SDK 12.1 which requires xcode 10.1: https://developer.apple.com/ios/submit/

I'm not 100% sure how the change in swift version affects the cordova plugins. I'm more concerned about plugins not managed by cordova nor meteor. I hope my hunch that it might be a lot of work to be wrong

hexsprite commented 5 years ago

FYI You can install Xcode 10.1 manually from Apple Developer portal: https://developer.apple.com/download/more/

davidecantini commented 5 years ago

As @rj-david mentioned, Apple requirements are a concern. It's just a matter of time and Swift 3 will not be accepted any more. What will happen at that point? I think it's wise to start working on supporting the latest Swift.

rj-david commented 5 years ago

I got the chance to make some tests today and here is what I discovered when using xcode 10.1

  1. In the project workspace in xcode, there was a warning asking the user to convert from Swift 3 to Swift 4.2.
  2. Clicking on this, a dialog guided me on the conversion with a few files requiring changes (automated)
  3. I proceeded with the suggested file changes
  4. When I went to the Build Settings tab, I could see that Swift Language Version is set to Swift 4.2
  5. I run the project and the build succeeded

My current conclusion is that changing the related files (number 2 above) to the suggested fixes will make meteor compatible to xcode swift 4.2

rj-david commented 5 years ago

Made the PR: https://github.com/meteor/cordova-plugin-meteor-webapp/pull/77

alanning commented 5 years ago

Nice! Were you able to get the unit tests working? I noticed CI is failing so I'm guessing the unit tests need to be updated as well.

rj-david commented 5 years ago

I did not (first time making a PR). I can only deal with it on Monday as I didn't bring home my mac as it isn't my main laptop.

I checked that the changes from swift 4 to swift 5 are also very easy. But I'm not 100% sure if we don't need to update cordova-ios

wreiske commented 5 years ago

FYI, Swift >= 4 breaks the hot-reload

2019-04-02 18:15:21.652700-0400 AppName[3914:2044352] ERROR: Method 'onError:' not defined in Plugin 'WebAppLocalServer'
2019-04-02 18:15:21.652768-0400 AppName[3914:2044352] FAILED pluginJSON = ["WebAppLocalServer304030848","WebAppLocalServer","onError",[]]
2019-04-02 18:15:21.667673-0400 AppName[3914:2044352] ERROR: Method 'onNewVersionReady:' not defined in Plugin 'WebAppLocalServer'
2019-04-02 18:15:21.667783-0400 AppName[3914:2044352] FAILED pluginJSON = ["WebAppLocalServer304030849","WebAppLocalServer","onNewVersionReady",[]]
2019-04-02 18:15:22.314741-0400 AppName[3914:2044352] ERROR: Method 'checkForUpdates:' not defined in Plugin 'WebAppLocalServer'
2019-04-02 18:15:22.314793-0400 AppName[3914:2044352] FAILED pluginJSON = ["WebAppLocalServer304030850","WebAppLocalServer","checkForUpdates",[]]
2019-04-02 18:15:40.870345-0400 AppName[3914:2044389] App startup timed out, reverting to last known good version
2019-04-02 18:16:26.735677-0400 AppName[3914:2044352] ERROR: Method 'checkForUpdates:' not defined in Plugin 'WebAppLocalServer'
2019-04-02 18:16:26.735864-0400 AppName[3914:2044352] FAILED pluginJSON = ["WebAppLocalServer304030852","WebAppLocalServer","checkForUpdates",[]]
rj-david commented 5 years ago

FYI, Swift >= 4 breaks the hot-reload

We need someone who is adept to Swift to help fix the issue

davidecantini commented 5 years ago

Hello guys, any update on this? Meteor needs to support Swift 4+ as soon as possible, because now there is also this other issue.

domramirez commented 5 years ago

@rj-david @wreiske Is the hot reload the only known issue with @rj-david's fixes? This is definitely a critical issue now.

I might be willing to temporarily do without some functionality related to Meteor's environment rather than uninstalling->installing->uninstalling->installing xcode every time I need to deploy.

rj-david commented 5 years ago

I made a new PR: https://github.com/meteor/cordova-plugin-meteor-webapp/pull/78

  1. Updated swift compatibility to version 4.2
  2. Fixed issues as posted by @wreiske with HCP
  3. Fixed the test scripts to use Xcode 10.1 and ios-sim 8.0.0 (ios-sim has a pending issue with Xcode 10.2) - all tests succeeded

@benjamn, can you take a look?

alanning commented 5 years ago

@rj-david, @benjamn Thank you for your work on this! I just tried again with Xcode 10.2, Meteor 1.8.1, and webapp 1.7.4 (which uses @rj-david's awesome PR in cordova-plugin-meteor-webapp 1.7.0 under the hood) and everything builds correctly.

I think this issue can also be closed now that webapp 1.7.4 is published, is that correct?

frankwo1 commented 5 years ago

Sorry but does anyone know when webapp 1.7.4 will be published?

frankwo1 commented 5 years ago

@alanning @rj-david @benjamn Does anyone have a recommended course of action?- this does not work for me

davidecantini commented 5 years ago

@frankwo1 Have you tried this already?

meteor update --release 1.8.1-issue-10516.0

frankwo1 commented 5 years ago

@davidecantini Thanks - no not with that version of Meteor (am using 1.8.1) - I'm going to try it now

frankwo1 commented 5 years ago

@davidecantini Thanks - it seems to work although I think I broke my key chain somewhere since I am getting this error "iPhone has denied the launch request. Internal launch error: process launch failed: failed to get the task for process 371" I will reset the keychain