When I run my React Native application WebStorm starting an iPhone X simulator by default. WebStorm's React Native documentation states that:
If you selected the Build and launch checkbox, choose the target
platform, Android or iOS. Depending on your choice, WebStorm will run
the bundler with react-native run-ios or with react-native run-android.
Optionally, type the arguments to be passed to React Native, for
example, specify the simulator type through the ‑‑simulator flag:
‑‑simulator="iPhone 4s".
I have set my flag to iPhone Xs Max as shown below:
But it is still starting iPhone X:
react-native-cli run-ios "‑‑simulator=iPhone Xs Max"
info Found Xcode project MyProject.xcodeproj
info Building using "xcodebuild -project MyProject.xcodeproj -configuration Debug
-scheme MyProject
-destination id=0299DF16-DD84-40FB-8B37-55FC7EFCE271
-derivedDataPath build/MyProject"
The id 0299DF16-DD84-40FB-8B37-55FC7EFCE271 is id of iPhone X.
How can I change this?
I found the problem. What was wrong is dashes of flag simulator. When I copied the code from documentation it had short dashes ‑‑simulator. Correct one should be --simulator.
Related
I've recently started learning Swift and SwiftUI for iOS development and I completely understand how to run my apps for testing using XCode. You just click the play button with whatever simulator device is selected. However, I really don't like using XCode. I want to use VSCode for my development. Looking online I can find very complicated tutorials on how to build my project for release on the App store or "Ad-Hoc" from the terminal. But, I don't think this is what I need. I'm wondering if there is a way to build and run my app from the terminal on to a simulator or personal device (connected with USB)? I understand I can just have XCode open on the side and run it from there while developing from VSCode, but, my computer is kind of old and having both those apps open makes my fans go crazy.
You can follow this guide on how to build your project using xcodebuild.
Assuming you are in the directory with the .xcodeproj file, the command will look something like this:
xcodebuild -destination "platform=iOS Simulator,name=iPhone 14 Pro Max,OS=16.0" -scheme YourScheme SYMROOT="./build" build
Of course, you can choose any simulator you like. You can find a list of the simulators by doing xcrun simctl list.
The built app will be located in a folder called build/Debug-iphonesimulator, or build/Release-iphonesimulator, depending on your default configuration. The configuration can be set by the -configuration option.
Now you can launch the simulator. Here is a guide for that. Basically, you just specify the UUID of the simulator (again you can find this using xcrun simctl list), and then launch Simulator.app. Example:
xcrun simctl boot 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
To install the built app, you also need the UUID (see also this answer)
xcrun simctl install 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1 build/Debug-iphonesimulator/YourApp.app
Finally, you launch your app by specifying the UUID of simulator, and the bundle ID of your app (source)
xcrun simctl launch 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1 com.mydomain.YourAppBundleId
react-native-cli: 2.0.1
react-native: 0.58.4
When I use react-native cli invoking build ios to simulator, it is not building any app. It just opens IOS simulator.
This is everything what i get:
Found Xcode project HelloWorld.xcodeproj
Launching iPhone 6s (iOS 12.1)...
Building using "xcodebuild -project HelloWorld.xcodeproj -configuration Debug -scheme HelloWorld -destination id=32CE8569-3EE3-4DDD-9963-E0ED0E8DA946 -derivedDataPath build"
User defaults from command line:
IDEDerivedDataPathOverride = /Users/tokra/Documents/Code/bitbucket.fork/rn-test/HelloWorld/ios/build
I remember it built only once, since then I cannot force rebuild.
Is there any way how to force build xcode in cli using react-native?
I'm trying to build and archive (in Release and Debug mode) an ios project generated with apache cordova 4.0.0, via command line tool xcodebuild
These commands work ok:
cordova platform add ios
cordova prepare ios
cordova build ios
The ios project generated by cordova has a scheme called iHogar. After that, when I try to launch this command on the console:
xcodebuild -scheme iHogar -sdk iphoneos -configuration Debug
CODE_SIGN_IDENTITY="iPhone Distribution: S-N-A L-C-A, S- CO-P-Ñ-A DE
SE-U-O- Y R--A-E-U-OS (xxxxxxx)"
It stops at the beginning of the execution, and does not continue. The value of param CODE_SIGN_IDENTITY is modified due to privacy reasons.
Here is the output of the command, through console:
Build settings from command line:
CODE_SIGN_IDENTITY = iPhone Distribution: S-N-A L-C-A, S- CO-P-Ñ-A DE SE-U-O- Y R--A-E-U-OS (xxxxxxx)
SDKROOT = iphoneos8.1
And stops there without finishing the command (it hangs) , only stops with crtl+C
The certificate is ok, and also the provisioning profile. If I open the project with Xcode (version 6.1) everything goes ok, I can build and archive it without problems, with the same certificate and provisioning profile.
Has anyone experienced this behavior?
Thanks in advance
I have resolved this issue. The problem was that the cordova generated ios project hasn't got schemas. Those are created the first time you open the project with XCode. When the app has been created by cordova, is only created with targets.
In this scenario, that the generated app cannot be opened with XCode with human interaction, is better to build the app with the target option, like this:
xcodebuild -xcconfig "cordova/build.xcconfig" -project "iHogar.xcodeproj" ARCHS="armv7 armv7" -target "iHogar" -configuration Debug -sdk iphoneos build VALID_ARCHS="armv7 armv7s" CONFIGURATION_BUILD_DIR="build/device"
It's important to have the certificate to sign the app installed in the keychain, and the related provisioning profile downloaded.
I know you got around your issue, but as this is quite recent, have you considered upgrading to Cordova 5.1.1. This will build and code sign the app without the need to go into XCode.
You can run the Swift REPL with a couple of different options for the --sdk option. You can run:
xcrun swift -v -sdk $(xcrun --show-sdk-path --sdk iphonesimulator)
or
xcrun swift -v -sdk $(xcrun --show-sdk-path --sdk macosx)
There is also
xcrun swift -v -sdk $(xcrun --show-sdk-path --sdk iphoneos)
Which doesn't seem to work very well and causes lots of errors.
How will my output differ when using the iphonesimulator sdk vs the macosx sdk?
The desktop, device emulator and device hardware are different build targets:
SDK Target
macosx OSX Desktop
iphonesimulator iOS Simulator
iphoneos iOS Hardware
Currently, xcodebuild supports these platforms:
OS X The local Mac, referred to in the Xcode interface as My Mac, and which supports the fol-lowing following
lowing keys:
arch The architecture to use, either x86_64 (the default) or i386.
iOS An iOS device, which supports the following keys:
name The name of the device to use.
id The identifier of the device to use, as shown in the Devices tab of the Xcode
Organizer.
iOS Simulator The iOS Simulator, which supports the following keys:
name The full name of device to simulate, as presented in Xcode's UI.
OS The version of iOS to simulate, such as 6._, or the string latest (the default) to
indicate the most recent version of iOS supported by this version of Xcode.
This is abstracted in the IDE:
For iOS, Xcode automatically switches between the iOS Simulator SDK and the device SDK, depending on where you intend to run your app. You don’t need to select these settings manually.
References
Xcodebuild Command Line FAQ
Mac OSX Glossary
XCode Release Notes Archive
Configuring a Project for SDK-Based Development
When I try to build my xcode project using the following command:
xcodebuild -workspace "Converse.xcworkspace" -sch
eme "Converse" -configuration “Debug” -sdk iphonesimulator7.1 -arch i386 ONLY_
ACTIVE_ARCH=NO
It builds fine, but when I try to double click on the app it generates, it says: You can’t open the application because it is not supported on this type of Mac. Does anyone know why this is happening?
iOS apps need the simulator to run. You can just, as you said run them from Xcode. If you do not have the project then you need to deploy them like :
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication /Path/ToIso.app/AppName
Use Xcode, not xcodebuild, to run your app on the simulator.