NET from a single shared codebase. App not run in visual studio emulator for androiXamarin.Forms is an open source mobile UI framework from Microsoft for building iOS, Android, & Windows apps with. The first time a Xamarin.Android app is run in the emulator, the Xamarin.Android shared runtime for the targeted API level is installed, followed by the application. The emulator may be left running: it is not necessary to shut it down and wait for it to restart each time the app is launched.I quickly dismissed the possibility of bad “new Xamarin.Forms project” template – Internet would be screaming in such case.When you launch the emulator the word android will appear on the screen first. So, no packages for some reason. Since I had no idea what that message wanted to tell me I went checking for references and I quickly saw that nor Android nor iOS had any NuGet reference present albeit the packages were listed as installed.
Android Emulator For Xamarin On Execution Failed After Closing Mac Given MySo I had to figure it out on my own.First hint was that XMA required me to type in the username/password for connecting to the Mac. But my problem wasn’t listed there or anywhere else. Basically I could connect through Xamarin Mac Agent (XMA) through Visual Studio but then the build would fail saying that it couldn’t log to target Mac given my username.For starters one might read Connecting to the Mac and Connection Troubleshooting topics. Which was correct, but I wasn’t using that source at all.It turns out that once disabling that (faulty) source, NuGet was able to restore the packages and project was building.Actually it was a combination of two problems combined – one was that missing source that prevented NuGet to download packages and the other problem was that the required NuGet packages weren’t cached locally on my computer – if they were I believe it would work regardless of the faulty source.I’ve been digging a bit into problems of connection between Visual Studio (Xamarin.iOS) and a Mac and wanted to share a few tips here.It all started with my Visual Studio being unable to build an iOS application due to the connection issues. If the Android emulator you are using is on older and unsupported Mac OS X version (10.9) then remember that you After tinkering a bit, I saw that Package Manager window was saying that it can’t find a reference to NuGet Source for one of my sources. First thing was inspecting the log files (VS Help/Xamarin/Open Logs…). For me it was asking for credentials each time I started Visual Studio.After reading, digging and googling I understood that XMA is using SSH tunnel to connect to the Mac. When configured properly it shouldn’t ask for credentials, perhaps only for the first time. Since the public key is on host, the problem obviously has to do with the host – but why since it was working from command prompt. Next thing to try was Xamarin’s own SSH diagnostics app (provided as C# sources – kudos) which would throw Permission Denied (publickey) upon Connecting to host. Next thing was – checking the SSH connectivity (command prompt, ssh Using my default private key I had no problems connecting to the Mac but Visual Studio kept failing the build process. And as anybody would guess, it was missing Xamarin’s public key. The solutionTime for looking at Mac, specially in file /Users/username/.ssh/authorized_keys where public keys for my profile are stored. So definitely a key issue. (replace %LocalAppData% with value) ssh –i %LocalAppData%Xamarin/MonoTouch/id_rsa. So next thing I tried was connecting through command prompt/ssh using –i PATH argument (forces what key is used), i.e. And it isn’t my default one, which I tested the connection with.The thing is that XMA is using its own private key which you can find it at %LocalAppData%Xamarin/MonoTouch/id_rsa. The causeThis let me thinking, why does it usually works without intervention. And so did XMA from Visual Studio. This time the ssh command line tool connected without problems. Google chrome free for macThe security considerationsLet me repeat what happens when first time connecting to Mac. It’d certainly spared me some time. I wouldn’t mind a clear warning: “ hey dude, XMA was unable to modify your authorized_keys file, please enter this public_key manually”. This was my case, I had authorized_keys file as read only. But what happens if the authorized_keys file is read-only? Ha, nothing, a log entry and that’s it. XMA first tries using its private key, if it doesn’t succeed it tries to cat the public key portion to authorized_keys file on Mac (probably using the credentials you have to enter ). It still would have to type in password for su access, but nevertheless, this isn’t something that should be taken easily IMO.I certainly wish that the connection mechanism was better documented and people were aware what’s going on. Theoretically an app that user runs (no admin privileges required) could use the key (or worse, copy it through the Internet) to connect to your Mac and gain your credentials on the Mac, which are most probably administration ones. To make things complicated, the private key in question isn’t password protected. Were you aware of that? No? Neither was I. They won’t react to changes and it makes sense, since underlying OS or device type don’t change during runtime.So something different is need. They do their work once and that’s it. There is support for different layout when it comes Phone vs Tablet ( OnIdiom) or when it comes to different OS ( OnPlatform) but the thing is that these guys are static. The thing is that there is currently no support for this. Also, an option to use password protected private key would be much more secure.In case you’ve been wondering how to achieve different XAML layouts for different device orientation with Xamarin.Forms (just Forms from now), here is a solution. Now this information can be used to achieve the dynamic layout changes.For that purpose I’ll use a Grid ContentView derived class that can be nicely used with XAML. Public enum RotationPublic static EventHandler RotationChanged And here is the OS specific part where you set the orientation.Android version: public class MainActivity : AndroidActivityProtected override void OnCreate (Bundle bundle)Public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)Switch (WindowManager.DefaultDisplay.Rotation)Orientation.Rotation = Rotation.Rotation0 Orientation.Rotation = Rotation.Rotation90 Orientation.Rotation = Rotation.Rotation180 Orientation.Rotation = Rotation.Rotation270 Windows Phone version (note that you have to set SupportedOrientations=”PortraitOrLandscape” in your MainPage.xaml to enable rotation of the page): public partial class MainPage : PhoneApplicationPageContent = App16.App.GetMainPage().ConvertPageToUIElement(this) If ((Orientation & PageOrientation.PortraitUp)App16.Orientation.Rotation = Rotation.Rotation0 Else if ((Orientation & PageOrientation.PortraitDown)App16.Orientation.Rotation = Rotation.Rotation180 Else if ((Orientation & PageOrientation.LandscapeLeft)App16.Orientation.Rotation = Rotation.Rotation90 App16.Orientation.Rotation = Rotation.Rotation270 Protected override void OnOrientationChangedSadly I have no iOS device at this time, but it should be pretty easy to support it as well.At the beginning of the page/activity and each time orientation changes the current rotation is sent to Orientation class in PCL.At this point we have the rotation information and event RotationChanges that notifies about changes in rotation. It is a twofold solution.Here is code that exists in PCL project and isn’t OS specific.
0 Comments
Leave a Reply. |
AuthorLara ArchivesCategories |