In my 13th lesson in the book "App Development With Swift" (using Xcode 8) my assignment was to build a QuestionBot app. Sometimes when I wanted to check myself I ran the simulator, and every time when I tried to run it, it asked me to "stop" and then run again. I pressed the button that stops the simulator (the square) and it said "build failed". Since then every time when I tried to run, it said the same ("build failed").
every information will be great, thank you
Related
Yesterday, I was working on my app and all was well. I had discovered two commands that would reliably start the remote debugger and run the iOS simulator. These two commands had been working reliably for about 48 hours, and I was so happy that I saved these commands in a text file on my desktop for easy access:
open "rndebugger://set-debugger-loc?host=localhost&port=8081"
react-native run-ios
Then I made a terrible mistake: I went to sleep. When I woke up, the commands no longer work. The first command launches the debugger, but the second command ("react-native run-ios") produces a variety of results, none helpful (see note below). At best, the simulator launches, but my app is a white screen.
After trying various things (listing processes to see if there is something to kill, rebooting the machine multiple times, etc) I decided to nuke my app and start over. So, I archived my app and created a new app with "create-react-native-app AwesomeProject" etc. I changed into the project directory and then almost ran "npm start" (as the docs suggest) but the terminal output suggested "yarn start" so I went with that. This gave me a QR code for an expo, but I still wanted the simulator on the screen. So I went back to the commands that were so reliable for about 48 hours:
open "rndebugger://set-debugger-loc?host=localhost&port=8081"
react-native run-ios
But they just don't work anymore. At best, I can get a simulator on the screen, but if I navigate to my app in the simulator, it is a white screen. I have tried "Erase all content and settings" in the Hardware menu for the simulator, quit the simulator, etc.
Will I ever be able to view the simulator on my screen again? Do I need to uninstall expo to get the on-screen simulator back? Should I just not sleep anymore? Will I ever reach I point where I can just wake up in the morning, quickly start the simulator and then be an app developer? Should I just give up on the simulator and adapt my workflow to use a physical device as the simulator?
Edit: To clarify, the variety of results include: simulator not appearing on the screen; simulator appearing and opening to the desktop of the iPhone, but when I navigate to the app and open it, it's a white screen; simulator appearing and app starting without my navigating to it, but it's a white screen.
Edit 2: Here is another data point. Just now I deleted my app again and created a new one with create-react-native-app. I then changed into the project directory and ran npm start. I then get a QR code and have confirmed I can open the app in my device using expo. And I see this error in my terminal, which might be unrelated to this issue:
2:31:11 PM: Error: './assets/icons/icon.png' could not be found, because './assets/icons' is not a subdirectory of any of the roots ('/Users/me/Apps/MyAwesomeApp')
2:31:11 PM: at /Users/me/Apps/MyAwesomeApp/node_modules/metro/src/Assets/index.js:192:11
2:31:11 PM: at Generator.next (<anonymous>)
2:31:11 PM: at step (/Users/me/Apps/MyAwesomeApp/node_modules/metro/src/Assets/index.js:329:347)
2:31:11 PM: at /Users/me/Apps/MyAwesomeApp/node_modules/metro/src/Assets/index.js:329:507
2:31:11 PM: at <anonymous>
So I have a working app and can test it with my device, but it would be nice to have the simulator on my monitor. However, "react-native run-ios" is not giving me that.
(Alas, this process below is not working reliably. It worked once. Then I tried to integrate opening the debugger into this process. A short while after posting this StackOverflow answer, I ran 'open "rndebugger://set-debugger-loc?host=localhost&port=8081"'. This seems to have broken the simulator, though the app still works in my device. I am now again trying to figure out how to get the simulator working. For a moment, the following seemed like the correct answer but it's no longer working -- now I get a "Runtime is not ready for debugging" red screen.)
I found a process that in this particular case gets the simulator working again (Update: It doesn't work. See my note at the top of this answer). I have expo on my Mac and on my devices, so these instructions assume you have the expo app:
In terminal, create an app with create-react-native-app. Do not sudo. No need to be root. Just a normal user.
Then, just like the react native docs say, change into the project directory and run 'npm start'. The terminal output suggests 'yarn start', but 'npm start' works for me.
When the expo QR code appears in the terminal output, use it. That is, install your app on a device by using the expo app to read the QR. Then, I think my next step was to open the expo app and then tap "Go to expo home" and then tap on my app to open it. And the app started up just fine.
Then, the real magic happens... I change into the project directory in a separate terminal tab and run "react-native run-ios". And then the simulator opens on my monitor and my app starts right up.
Thus, it appears that perhaps I had to run the app on my device first before I could open simulator on my Mac. Running the app on my device seems to get something unstuck.
Install the Chrome browser. Expo expects Chrome to be installed. With Chrome installed in Mac OS, a remote debugger will open in Chrome any time you run the simulator with react-native run-ios.
When running my App, I'll get this occur 3 out of 4 attempts to run the app from xcode. Hitting enter & CMD-R will sometimes generate the error again, and sometimes (rarely) actually run & debug the code. This happens with both an iPhone 6 device (8.3) and a iPhone 5 device (8.2).
While it's not a show stopper, its adding to the development cycle time. Anyone out there suffering the same issue, or anyone have a solution?
I've had this happen both with and without a watch extension, but it is more pronounced when working on an App with a watch extension.
While Watch connections can be inconsistent, it seems that keeping the Watch on the charger while debugging is a noticeable improvement. That's been my experience along with others who have comment in the Apple Developer Forums.
So here's my ritual on a "quick" turnaround for build & runs:
Open your app on the Watch
Press and hold the button below the crown until the Power Off options appear
Release the button and press and hold again. This will terminate the running app.
Build & Run from Xcode
On the Debug Navigator it will hang 9/10 times at the "Waiting to Attach" screen
Help Xcode a little bit by tapping on your app icon from your Watch home screen to open it, Xcode will promptly attach.
Your new build is now running.
I really hope they fix this in the next Xcode update but this is how it's currently working for me.
I keep getting the "The Simulator can't be launched because it is already in use." when trying to run my app, this only happens about 20% of the time but once so far the only way to get around it is to restart my Mac.
Tried the following but doesn't help:
Cleaning my build folder
Closing and re-opening xCode
Force close of simulator
I'm Using xCode 6 (beta 4)
Any Ideas for a solution that doesn't entail me restarting my Mac?
Thanks
"The Simulator can't be launched because it is already in use.”
This messege will be shown only if there is another xcode project that has launched simulator and hasnt stopped it yet, and u try to run the simulator from another xcode project.
Ideally stopping the simulator from the respective project(PS. not closing the application from the simulator, clicking the STOP button) would do it,
But if it still is working like that, then Closing the simulator, or resetting the simulator contents.
If that still dsnt work, then as a last resort i would ask u to reinstall Xcode, as if this problem keeps going on, then ur downloaded file might be buggy.
P.S if u opt to re-download n install xcode please keep backup.
Hope it solves it. Although i want your problem to be solved by step 2.
This normally just happens when running an app (project) on the simulator and then trying to run another app while the simulator is open (and normally is still within the first app you launched and it can't quit automatically). As long as you keep running the same app you shouldn't get this error and as soon as you run another app just make sure you've closed the simulator before or at least left the previous app with the home button.
Just Restart Your Mac , It Will Fixed
I had the same problem and fixed it without restarting. You just need to reset the content on ios simulator, exit xcode, and then to make sure that you've completely exited, right clicking on the xcode icon on your mac nav bar and click Quit. Open it back up and it should work.
I have been at this for hours and am about to start flipping tables. This problem cropped up out of nowhere after working on this app successfully for about a month. No changes to build settings or build schemes or anything that I can think of.
If I build and run the app on an iPhone 4 I have no problems at all. If I build and run the app on an iPhone5S it will:
On the first attempt: Build successfully, appear to install the app on the device and launch it, but then fail with "error: failed to launch '.../MyApp.app' -- NotFound".
On the second attempt: Build, run, have a happy little debug session and everything is perfectly fine and dandy.
On the third attempt: Build successfully, begin to launch the app, and then will fail with "error: failed to launch '.../MyApp.app' -- Failed to get task for process -1". The phone will then become unresponsive, and the only way to bring it back is a hard reset.
Once or twice throughout the past few weeks I've had this problem happen, but after resetting everything was fine. Turning on or off building for arm64 doesn't seem to make a difference, and I can't think of anything else that would be different between the two devices.
Even a hint would be appreciated.
UPDATE: I changed the build scheme to "Wait for app to be launched manually", and by launching it myself after it's been built it seems to avoid the crashing. Obviously this doesn't fix whatever the underlying problem is, but at least I can function now.
Looks like this is a known bug, and it's resolved in Xcode 5.0.2.
I'm experiencing this very same issue but the workaround I've found is to disconnect and reconnect the phone before running the app. Using this workaround, I haven't experienced the error as frequently as otherwise, but it's still a rather tedious process...
This problem is known back to first Xcode 5 Previews. It helps to disconnect and connect the phone again. MY worst experience was Preview 4 with iPad. It till happens occasionally, but very rare compared to before.
My app runs fine on the simulator. However, when I run it on my iPhone, it gets as far as displaying the splash screen and then just stays there. It's an iPhone 3GS and the software version is 5.0.1. That's what happens when Debugger = None. When Debugger = GDB, I get an error message, 'Thread 1: Program received signal: "SIGABRT"', which I have learned can mean almost anything. I'm running Xcode 4.2.1.
I'm coming off a long hard night of battling with this error message, which appeared seemingly out of nowhere in a stable mature app. I tried to roll back with time machine, I deleted the Derived data for my project in Organizer a few times and did some of the other stuff recommended in this thread.
XCode 4 hangs at "Attaching to (app name)"
It got ugly. For a while, I couldn't even reboot my machine. Eventually, I was able to relaunch finder and suddenly the Simulator was working again. Two more pieces of information, I used to have to click allow in two dialog boxes when running on my phone but now it's only one (the one about code signing, I forget what the other one was about). Second, I find all the build architecture target stuff confusing but I set all my Base SDKs to be latest iOS. Lastly, I tried Product --> Clean and then Build but that didn't fix it. As you may have gathered, I'm getting my butt kicked. Any help would be much appreciated.
Dessie
Many times I have experienced Xcode going "crazy" with a physical device connected. At times I saw the behavior you describes; other the app simply refused to start;
In all of those cases, I could fixed it in either of two ways:
disconnect the iphone and connect it again;
reboot the device.
This is a very common problem that is easily fixable.
1) remove the app from the device
2) reboot the device
3) close Xcode and you must restart, logging out will not work