ios-control / ios-sim

Command-line application launcher for the iOS Simulator
Apache License 2.0
1.5k stars 253 forks source link

iOS 11/Xcode 9 compatibility #218

Closed kelvindart closed 7 years ago

kelvindart commented 7 years ago

Expected behavior

To be able to deploy to the iOS simulator when Xcode 9 is installed with the iOS 11 SDK, with the ability to select the additional simulators from the list.

Actual behavior.

When I try to run cordova emulate ios without specifying a default device, I receive the following error:

No target specified for emulator. Deploying to undefined simulator

Device type "com.apple.CoreSimulator.SimDeviceType.undefined" could not be found.
[ERROR] An error occurred while running cordova emulate ios (exit code 1).

Despite there being default simulators installed, it appears like it is not selecting the first relevant simulator, instead, just whatever is at the top of the list.

If I run ios-sim showdevicetypes, I am returned the following list, which is omitting the new simulators (iPhone 8, iPhone 8 Plus and the iPhone X), and has the Apple-Watch listed at the start (which, as explained below, is now the default):

Apple-Watch-38mm, watchOS 4.0
Apple-Watch-42mm, watchOS 4.0
Apple-Watch-Series-2-38mm, watchOS 4.0
Apple-Watch-Series-2-42mm, watchOS 4.0
iPhone-5s, 11.0
iPhone-6, 11.0
iPhone-6-Plus, 11.0
iPhone-6s, 11.0
iPhone-6s-Plus, 11.0
iPhone-7, 11.0
iPhone-7-Plus, 11.0
iPhone-SE, 11.0
iPad-Air, 11.0
iPad-Air-2, 11.0
iPad--5th-generation-, 11.0
iPad-Pro--12-9-inch---2nd-generation-, 11.0
iPad-Pro--10-5-inch-, 11.0
Apple-TV-1080p, tvOS 11.0
Apple-TV-4K-4K, tvOS 11.0
Apple-TV-4K-1080p, tvOS 11.0
iPad-Pro--9-7-inch-, 11.0
iPad-Pro, 11.0

If I then run ios-sim start, it states:

--devicetypeid was not specified, using first available device: Apple Watch - 38mm.

I expect, because of this, it's trying to deploy the Cordova app to the Apple Watch, hazard a guess?

If I do specify an iOS emulator to deploy to, I receive the following:

$ ionic cordova emulate ios --target="iPhone-7"
...
No available runtimes could be found for "iPhone 7".
[ERROR] An error occurred while running cordova emulate ios --target iPhone-7 (exit code 1).

Steps to reproduce the problem

As above (assuming Cordova and ios-sim are installed).

  1. Start a blank Cordova project: cordova start SimApp && cd SimApp
  2. Run the app: cordova emulate ios --target="iPhone-7"

System Specs

Please run the commands below in your Terminal.app and include it in the issue. Check when done and include results below.

1. system_profiler SPSoftwareDataType:

System Software Overview:

  System Version: macOS 10.12.6 (16G29)
  Kernel Version: Darwin 16.7.0
  Boot Volume: Macintosh HD
  Boot Mode: Normal
  Computer Name: Kelvin’s MacBook Pro
  User Name: Kelvin Dart (kelvindart)
  Secure Virtual Memory: Enabled
  System Integrity Protection: Enabled
  Time since boot: 1 day 6:13

2. ios-sim --version:

6.0.0

3. xcodebuild -version:

Xcode 9.0
Build version 9A235

4. xcode-select --print-path:

/Applications/Xcode.app/Contents/Developer

5. node --version:

v8.2.1

6. npm --version:

5.4.1
shazron commented 7 years ago

Investigating why it's not showing the new sims.

shazron commented 7 years ago

7 device types are skipped on this line: https://github.com/phonegap/ios-sim/blob/4bbe6b3307b594d9bf78775418fea139e71eabb1/src/lib.js#L330

iPhone 8, 11.0
iPhone 8 Plus, 11.0
iPhone X, 11.0
Apple Watch Series 3 - 38mm, watchOS 4.0
Apple Watch Series 3 - 42mm, watchOS 4.0
Apple TV 1080p, tvOS 11.0
iPad Pro, 9.3
shazron commented 7 years ago

If you run xcrun simctl list devicetypes you will see the new devices are curiously named (obfuscated?):

== Device Types ==
[..irrelevant device types removed...]
iPhone2017-A (com.apple.CoreSimulator.SimDeviceType.iPhone-8)
iPhone2017-B (com.apple.CoreSimulator.SimDeviceType.iPhone-8-Plus)
iPhone2017-C (com.apple.CoreSimulator.SimDeviceType.iPhone-X)
iPad Pro (9.7-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--9-7-inch-)
iPad Pro (12.9-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro)
iPad Pro (12.9-inch) (2nd generation) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--12-9-inch---2nd-generation-)
iPad Pro (10.5-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro--10-5-inch-)
Apple TV (com.apple.CoreSimulator.SimDeviceType.Apple-TV-1080p)
Apple TV 4K (com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-4K)
Apple TV 4K (at 1080p) (com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-1080p)
Apple Watch - 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-38mm)
Apple Watch - 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-42mm)
Apple Watch Series 2 - 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-38mm)
Apple Watch Series 2 - 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-2-42mm)
Watch2017 - 38mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-3-38mm)
Watch2017 - 42mm (com.apple.CoreSimulator.SimDeviceType.Apple-Watch-Series-3-42mm)

which don't correspond to the device names when running xcrun simctl list devices (this command lists devices per runtime version). I think this is a bug in xcrun simctl list devicetypes where they did not change the device type names properly. This is apparent in the Apple Watch Series 3 and the new 2017 iPhones, and also the "Apple TV 1080p" for tvOS 11.0.

Also, weirdly the 12.9" iPad Pro is this, just plain iPad-Pro: iPad Pro (12.9-inch) (com.apple.CoreSimulator.SimDeviceType.iPad-Pro)

"iPad Pro, 9.3" is similarly missing in devicetypes since it is now iPad-Pro--9-7-inch-

shazron commented 7 years ago

I hate to do this, but we may have to do a mapping function to match the mismatched devicetypes.

shazron commented 7 years ago

See #219 PR, fixes this issue

kelvindart commented 7 years ago

Wow - rapid response :) thanks @shazron. I will check it out. How do I raise the bug against Xcode, if this is Apple's doing?

kelvindart commented 7 years ago

I have just seen you were up late fixing this - thanks for the dedicated effort.

jmargolese commented 7 years ago

I have installed ios-sim v6.1.1 and am seeing exactly the same behavior as @kelvindart in the OP above.

I am able to launch the simulator from Xcode 9, just not from the cli.

Is there something else that needs to be done on my end to resolve this?

thx

shazron commented 7 years ago

Not enough info. Are you using cordova-ios? There needs to be a platform update since ios-sim is baked in there.

MaxDaten commented 7 years ago

@shazron same probleme here, and yes I'm using cordova-ios. So we have to wait for an platform update…

kelvindart commented 7 years ago

@jmargolese and @MaxDaten, since updating to ios-sim@6.1.1, it works fine for me.

Make sure to follow @shazron's point on the platform update (i.e. update cordova-ios to the latest, cordova-ios@4.5.0)

First, check which version you are running in your local project:

$ cordova platforms

Then remove it, and add the latest version:

$ cordova platform rm ios
$ cordova platform add ios@4.5.0

This will install the latest, which is compatible with Xcode 9/iOS 11 and sims. Also, follow the point on Cordova's blog (https://cordova.apache.org/announcements/2017/09/08/ios-release.html) about cordova-plugin-console.

I believe the console is now integrated into the platform to use window.console.log (is that right @shazron?).

kelvindart commented 7 years ago

There is a minor issue when running:

$ ios-sim showsdks

But I will open a separate issue for this.

KevinBeckers commented 7 years ago

Using 4.5.0 solves the issue for me, but forces me to rollback to use 4.4.0 because of: duplicate symbol _OBJC_CLASS_$_CDVLogger

Issue #12849 Solution: #12849 (comment)

jmargolese commented 7 years ago

I can't tell if 4.5.0 solves the problem. After following @kelvindart 's suggestions, the build command fails with the same problem @KevinBeckers reports above.

MaxDaten commented 7 years ago

@kelvindart it works for me with ios@4.5.0. Thanks!

shazron commented 7 years ago

All, remove the cordova-plugin-console plugin. See the cordova-ios@4.5.0 blog post: http://cordova.apache.org/announcements/2017/09/08/ios-release.html

KevinBeckers commented 7 years ago

@shazron This fixed my issue.

jezmck commented 7 years ago

Although my issue isn't quite the same as the original issue, it seems likely related, especially re @shazron's fix.

I get No available runtimes could be found for "iPhone2017-C". after running cordova run ios --target="iPhone-X"

I've removed cordova-plugin-console. I have

Any suggestions?

shazron commented 7 years ago

@jezmck ios-sim has been updated in cordova-ios master branch. Unfortunately you will have to wait for cordova-ios@4.5.1 release (we are starting the vote tomorrow, so prob released next week) or just cd platforms/ios/cordova && npm install ios-sim@latest in your project

jezmck commented 7 years ago

That's amazing, thank you!

Ericdowney commented 7 years ago

I'm running an ionic app.

Setup

I am also receiving the No available runtimes could be found for "iPhone2017-C". when I run ionic cordova run ios --target iPhone-X

I ran the cd platforms/ios/cordova && npm install ios-sim@latest command and then when attempting to run the app I received this error:

Error: tsconfig: Cannot read file '/platforms/ios/cordova/tsconfig.json': ENOENT: no such file or directory, open '/platforms/ios/cordova/tsconfig.json'.

Any ideas?

PeterStegnar commented 7 years ago

@Ericdowney Looks like interesting situation ..

I suggest that you do:

I had similar problem liek you, and for example I got a swift version error in xcode (that I have unsuported swift 2 code ...) then I set in xcode in project config to swift 3.2 and then it started to work. So in the end check generated project in xcode.

brandyscarney commented 7 years ago
Error: tsconfig: Cannot read file '/platforms/ios/cordova/tsconfig.json': ENOENT: no such file or directory, open '/platforms/ios/cordova/tsconfig.json'.

@Ericdowney Make sure you change directories back to the root of your project before running the ionic cordova run command. I ran into the same error, and running it from the root of the project works. I brought this up to the team (I work at Ionic) to see if we can resolve the need to run this at the root.

ariel-ibarra-jd commented 7 years ago

If you are getting: No available runtimes could be found after running: cordova run ios --target="iPhone-#"

Try the approach suggested by @shazron cd platforms/ios/cordova && npm install ios-sim@latest

herberzt commented 7 years ago

I ran: cd platforms/ios/cordova && npm install ios-sim@latest and this works for iPhone-6-Plus but it's still failing when I try to emulate iPad-Pro. Any suggestions?

surajpindoria commented 7 years ago

Hey @herberzt,

I just tried this and it launched in the simulator just fine. What is the error message you are seeing?

herberzt commented 7 years ago

hey @surajpindoria sorry I just now saw this.

when i run : $ phonegap run ios --target "iPad-Pro" --emulator

I get a large thing of output but the main error at the bottom is: Device type "com.apple.CoreSimulator.SimDeviceType.iPad-Pro" could not be found.

surajpindoria commented 7 years ago

@herberzt, I just tried this again in a different project and was actually able to see the same error as you. But I was able to get rid of it by removing the iOS platform and then re-adding it. Make sure you are using the latest version, cordova platform add ios@latest.

herberzt commented 7 years ago

@surajpindoria okay I will give this a try. Thank you.

herberzt commented 7 years ago

@surajpindoria I took your guidance and did the following:

$ rm -rf platforms/ios $ phonegap platform add ios@latest $ bin/clean-build.sh which runs a bunch of commands and essentially gets cocopods in place etc.

went to go run the simulator again and I'm still getting the same error message.

surajpindoria commented 7 years ago

Hmmm, are you able to deploy to the iPad Pro emulator directly from Xcode? You can open your project in Xcode by running open <project-dir>/platforms/ios/<project-name>.xcworkspace.

surajpindoria commented 7 years ago

@herberzt Just noticed something on my machine that could explain why you are not able to launch the iPad Pro emulator. Can you run ios-sim showdevicetypes. On a machine using Xcode 9.0 I see an option for just plain iPad Pro. But on another that is using Xcode 9.0.1 I do not see it, but instead see iPad-Pro--10-5-inch- and iPad-Pro--12-9-inch---2nd-generation-.

This could explain why you are not able to launch the emulator.

holographix commented 6 years ago

Had this issue today, after updating to ionic 3.19.0. Using the approach suggested by @shazron worked out

cd platforms/ios/cordova && npm install ios-sim@latest; cd ../../../

ghost commented 6 years ago

when I run ionic cordova build ios --prod. I have a error

cordova build ios Error: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

[ERROR] An error occurred while running cordova build ios (exit code 1).

how to handle this ?

shazron commented 6 years ago

@pangjianfeng this is not a Cordova issue tracker. Looks like you need to install the full Xcode and for example put it in /Applications. Then sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/

shabeer3508 commented 4 years ago

@jezmck ios-sim has been updated in cordova-ios master branch. Unfortunately you will have to wait for cordova-ios@4.5.1 release (we are starting the vote tomorrow, so prob released next week) or just cd platforms/ios/cordova && npm install ios-sim@latest in your project

Thank you saved my day.