Xamarin Forms app not showing in iOS simulator - xamarin

I've got a Xamarin Forms app that previously worked well on both android and iOS simulator. After updating VSCode and XCode on Mac, I'm not able to launch it again.
The app builds well, with no errors, but with a warning that says:
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Xamarin.iOS". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. (MSB3245)
Nevertheless, it compiles, but when I launch the app on debug (or release) mode, it launches the iOS simulator, and then I can see the pause and stop buttons on VSCode as it was running, but the app is not installed in the iOS simulator and I see no changes on the simulator, just the main screen of iOS.
No breakpoints are active and, if in Windows I connect Visual Studio 2017 to a MAC virtual machine, I can launch the app, but it's pretty slow, so I need it to work on the MAC VM.
I've also tried to reinstall XCode and to reset settings on iOS simulator with no luck.
Any thoughs on what could be causing this problem?

First, make sure that all the tool versions are up to date. If the problem persists, you can delete two folders of bin and obj under the iOS project. They retain the old version of compilation information. Once the deletion is complete, you can rebuild your project.

I've solved it. It seems that visual studio didn't have permission to open the default projects folder (I don't know why this changed when I updated it). I've changed the default folder to another path, in my case, Downloads folder, and now the problem has gone. Pretty strange though.

Related

Getting 'Selected scheme "iosApp" does not support "iphonesimulator"' error for Kotlin Multiplatform

I am trying to run the initial example apps generated by the Kotlin Multi Platform Mobile plugin in Android Studio. I followed these steps for my environment setup. The Android Simulator runs correctly, but the iPhone Simulator does not. The Run Configuration has the following error:
Error: Selected scheme "iosApp" does not support "iphonesimulator"
When I run the configuration (ignoring the error), the iPhone simulator does open and appears to load iOS, but it never loads the "Hello, iOS" application that is in Android Studio.
What would cause this?
Version Information:
macOS 12.2.1
Android Studio 2021.1.1 Patch 2
Xcode 13.3
I fixed it with the following method.
Please close the Android Studio.
Go to ~/Library/LaunchAgents/ folder and delete com.jetbrains.AppCode.BridgeService.plist there.
Launch Android Studio with the KMM plugin again. It should work now.
From my tests, it seems that there may be multiple reasons for which we receive this error:
the root folder of the ios project has a different name than the .xcodeproject file. Sometimes it works even if they are different and maybe it matters if we change this name after the frameworks was already connected to the iOS project.
"Other linker flags" were manually copied and they were not copied using the copy button from the Connect the framework to your iOS project. This results to wrong data like:
"$(inherited)",
"-framework",
"shared\n",
instead of
"$(inherited)",
"-framework",
shared,
I managed to fix this by going into Edit Configurations on Android Studio and choosing the location of my XCode project file again. I believe this is an error of the KMM plugin in Android Studio and has yet to be fixed.
Updating Android Studio and KMM plugin worked for me.

Can't run a Xamarin App in iPhone Simulator from Visual Studio For Mac

In short: I am unable to run my app in the iPhone Simulator. There is no "Play button" (the triangle), only a Debugger button (hammer):
As you can see above I have "Generic Simulator". When I click on it, there is no list of various iPhones/iPads to choose from:
If I choose Android, I am able to run the app:
I have XCode installed. I ran XCode once.
I also installed the Command Line tools.
I created a new Xamarin Forms App:
Here are my iOS build options:
I am able to run the Simulator separately:
Creating an App in XCode and running in the Simulator works:
info.plist:
Prefrences -> SDK Locations -> Apple
Build -> Configurations:
Here is the kicker though. If I run a Xamarin App on my Windows machine using the iPhone Simulator on the Mac, it works!
What do I need to do so I can run my app inside the Simulator vis Visual Studio for Mac?
Few options you can worth to check. #WorldOfBasti suggested options plus following.
Configuration
Right click on the solution -> options -> Configurations -> Configuration manager -> ProjectName.iOS with Debug|iPhoneSimulator should be checked or if configuration "ProjectName.iOS with Debug|iPhoneSimulator" is not available then add this from General tab
Apple SDK path
Check Apple SDK path is set properly (Preference -> SDK Location -> Apple). It should have green tick mark with Xcode version and SDK path location.
Minimum system version (Deployment Target)
Change Deployment Target to minimum version (ie, lower than your simulator version)
Switch debug <-> release
Today I have also faced same issue which you are facing. I have switched debug to release, iOS to Android. Then reverted back to iOS and debug from the top device selection status bar. Then Simulator option was appearing. So, might be UI updated issue in Visual studio for mac. Please give a try.
I assume that you tried the basics things like restarting your Mac, etc. So here are a few things, that might solve your problem:
Check your build configurations, here is a good video
Close VS for Mac, start Xcode and create a test project which you run on a simulator. If it works try again in VS for Mac
Close VS for Mac, goto Xcode -> Preferences -> Accounts and download the manual profiles of your developer account. Try again in VS for Mac
Clean your project: In VS for Mac, goto Build -> Clean All. Then Close VS for Mac, goto your project folder and delete in "yourprojectname" and "yourprojectname".iOS all bin and obj folders. Try again
If all of this doesn't work, I would try to reinstall it (if you have any important projects, make a backup):
Uninstall VS for Mac and Xcode
Install Xcode again from the App Store
Install Visual Studio for Mac
Hopefully it works..
Looking at the Visual Studio for Mac logs, specifically the IDE log, I found this line ... 'The target name of simulated device could not be added because it's already cached'.
You are welcome to read through all of this ... but you may just want to go down to the Addendum 2 (final?) and see if that works for you ... it ends up being simpler and quicker than anything else I have found.
So, at first, I started clearing the cache with a 'xcrun simctl erase all' command from Terminal, and when I started Visual Studio for Mac I could run a Xamarin App, but launching the simulator took quite a bit of time.
So hare's something I found works that you might want to try ...
Close iOS Simulator on Mac (if any).
Close ALL copies of Visual Studio that are connected to the Mac ... either on the Mac itself or on another computer connected to the Mac (if any).
Start Visual Studio for Mac.
If you can't run a Xamarin App, Close Visual Studio for Mac.
Launch the Simulator manually (I have it in the Dock, so I just click it) ... wait for it to fully startup.
Now close the Simulator (from the Simulator menu).
Now restart Visual Studio for Mac.
If you still can't see the simulator devices to run on ... try the above steps one more time (this time you should only have to close Visual Studio for Mac followed by manually starting the Simulator, waiting for it to start, and then quitting the Simulator and finally restarting Visual Studio for Mac).
It still isn't great, but this has (so far) always worked for me. And the Simulator starts up substantially quicker then if I did a 'xcrun simctl erase all' command from Terminal.
Addendum: Most of the time the above works. But occasionally I still have to clear the cache from the Terminal with 'xcrun simctl erase all' command.
Also: I have also found (although maybe it's just my imagination) that clearing out the Visual Studio for Mac temporary .binlog files that are written in the 'T' folder will sometimes fix the problem (if you look at an IDE log from Visual Studio for Mac; right after the 'The target name of simulated device could not be added because it's already cached' message, you should see some .tmp files being created. The directory where they were created is the 'T' folder I'm talking about). I sometimes delete the tmp*.binlog and tmp*.tmp as a last ditch effort before using the 'xcrun simctl erase all' command to try to get back to where Visual Studio for Mac will see the iOS Simulator Devices.
Finally: This is really starting to feel like a bug in Visual Studio for Mac startup (or possibly during a iOS project load). The reason I say that is I can ALWAYS see the iOS Device list from Visual Studio for Windows (as long as I can connect to the Mac). In addition, I can leave Visual Studio for Mac running (even hidden) and test an app on the iOS Simulator from Windows, then, leaving the iOS Simulator Running on the Mac, run an App on Visual Studio for Mac. If there really were a 'caching issue' with the Simulator it seems to me I should have problems running anything on the Mac after using the iOS Simulator from Windows, but it always works. For now, I'm working on a single Xamarin Project on the Mac (and I don't use the Mac for anything else), So I just let Visual Studio for Mac 'open at login' (Dock setting) and automatically 'load previous solution on startup' (Visual Studio for Mac setting), hide Visual Studio for Mac (Dock Setting) and if I need it, Visual Studio for Mac is already loaded and able to see iOS Devices to run Apps on with a quick click on the Dock Icon.
Addendum 2 (final?): I have now found that if I just close a solution that I have open that shows 'Generic Simulator' and re-open it without exiting Visual Studio for Mac (sometimes I have to do it multiple times ... I think I've counted up to 5 times before it finally worked), it will start showing the device list and I can run the iOS app in the Simulator. I don't even have to close the Simulator if it's already running, which saves a bunch of time.
It still feels like a bug to me, I don't see why I would have to close/open a solution multiple times to get the iOS devices listed and be able to run an iOS app. What really gets me is if I reboot the Mac, don't open the Simulator and start Visual Studio for Mac, then open a solution, I still have to go through the close/re-open solution steps... sometimes more than once. The simulator is not set to auto start or anything like that. But, at least, it's getting simpler, and takes less time, to get to a point where I can run an iOS app.

Xamarin.Ios App terminates while starting (in Simulator and iPhone) only stating "The App has been terminated"

I am developing a Xamarin App for Android and iOS on windows. For iOS compiling, I pair with a Mac Mini.
I was forced to update MacOS, XCode, VisualStudio for Mac and therefore Xamarin. On Windows I also updated from Visual Studio 2015 to 2017.
After the updates, Android version works still fine.
The iOS App pairs, compiles and provisions successfully, but whe the App starts (either on simulator or real device), it shows the launch screen and after a few seconds quits back to home screen. It even says "successfully launched" but then terminates
The only logs I get are:
"The app has been terminated" -> on windows, in Debug Window
"Service exited due to SIGABRT" -> on mac, in simulator log file
I searched the web and tried lots of stuff:
Delete obj and bin folders
Clean, Rebuild, Restart VS, Restart Mac, Restart PC, Restart....
Deleted all Provisioning Files and Certificates, recreated them
Used Automatic provisioning, used Manual provisioning
Debug and Release Configuration
iPhone Simulator and Real Device
Sadly nothing worked and I cannot get more info why this happens.
Does somebody have or had the same issue and found a solution? Do you have suggestion what more I can try?
I would really appreciate any help.
Thanks
Edit:
As requested, a Screeshot of my build properties:
I am having the same issue. Restarting the device seems to be the only thing that works, but it's unreasonable to have to restart the device every time I want to run the debugger.
So I finally solved the problem...
I created a new iOS-Project from scratch, added the existing Xamarin.Forms project and copied the files from the original iOS project one by one. I also downgraded all firebase plugins from 5.x versions to the highest 4.x versions and xamarin forms from 3.x to 2.5.x and now the app runs in the simulator and bundle signing works also.
Thanks for your help, I hope my answer will help anyone with similar issues

iPhone Simulators not showing up in debug mode in Visual Studio for Mac. Xamarin.IOS

I developed an application in Xamarin.IOS on a windows machine, but the build time is getting ridiculous. So I decided to try to load and develop the solution on my Mac using VS. I have updated everything on my Mac (such as: Mac OSX, visual studio, and Xcode). I load the solution and everything builds, but no simulators show up in the target devices for debug mode. If I switch to release, the simulators show up, but not in debug. All provisioning files are downloaded and I have it set to Developer Automatic and Automatic.
Debug and Release are the only two build options. Debug|IPhoneSimulator is not one of them.
I also managed to get in this screwed up state with a new iOS project in VS4M. I tried changing various config settings to get it working, to no avail.
I added a new single-page iOS project to the same solution to see if the problem would persist. This fixed the problem in the new product and the existing project. I then deleted the extra project and called it good.
A stupid solution, to a stupid problem.
You will have to choose Build Configuration Debug|iPhoneSimulator, check the configurations and the target platform
Ended up creating a new project and edited the sln file to mimic what the defaults were for a new project then it started working.

Visual Studio 2017 / Xamarin fail to run app on iPhoneSimulator

** solved by trial and error, see comments **
Anyone who can help me troubleshoot the process of loading an iOS app into the XCode iPhoneSimulator?
Recently I set up the latest VS 2017 + Xamarin + XCode on my Mac Pro (MacOS 10.12.6 "Sierra"). I created a portable HelloWorld app with Xamarin, and it runs fine on the iPhoneSimulator, so everything is wired together correctly. I did also try a HelloWorld in XCode, it runs in the simulator too.
Today I loaded a sample app from GitHub, which is also a portable app supporting Android and iOS. After unloading the .Droid hive, I could successfully build it, no errors of any kind.
But if I try to run it in the iPhone simulator, the simulator starts, but then nothing happens any more, obvioulsly the app doesn't get executed, or an attempt to execute it is made, but fails silently. Other Xamarin apps appear on the iOS start screen, this one doesn't, it seems like it never reaches the simulator, or is rejected for some reason. System log shows nothing unusual. Usual steps to clean up the application and get an entirely new build (delete .obj and .bin and then rebuild all) have been tried, but no success.
Can anyone give me instructions ho I can do further troubleshooting? On Windows, I'd try to load the ready built apk into the simulator from a terminal window, sometimes this gives additional error infos, but on the Mac I have no idea how to accomplish this. What I can say though is that the build creates a ton of files in the debug directory (.exe, .dll, .pdb), but from ther I don't know how to proceed further.
The .Droid hive of the same application compiles and runs perfectly on my Windows host under the Android simulator.

Resources