Xamarin


Q:  When first building a Xamarin Forms project, I get an error “Cannot find aapt.exe”.  How do I fix this?

A:  No Android SDK is installed.  Even when checking all appropriate options in the Visual Studio installer, an Android SDK is not installed by default.  To fix this:

1. Goto Tools|Android|Android SDK Manager
2. On the Platforms tab, verify that at least one platform is checked, and to be safe, all of it’s child items.  If unsure what platform to use, goto project properties and use the Android version listed there.
3. On the Tools tab, ensure the following are checked:
4. Android SDK Command Line Tools
5. Android SDK Platform Tools
6. Android Emulator
7. Expand Android SDK Build Tools and check at least one entry.  Use an entry at v30 or later to avoid a subsequent error about the SDK being too old for Google Play and an error finding android.jar.
8. Click OK.
9. Wait for the components to install.  This will likely take 90 minutes on a 25 Mbps internet connection.

Q:  After a successful debug cycle, I get the warning “TargetFrameworkVersion (Android API level 29) is lower than the targetSdkVersion (30).”  How do I fix this?

A:  Follow these instructions:

1. In the Xamarin project properties, goto Application and note the “Compile using Android version” - this is the Target Framework.
2. Goto the Android Manifest tab and check the Target Android version.  Reduce this by by 1 from 30 to 29 as directed by the error message.

Q:  My emulated phone can’t access the Internet, how do I fix this?

A:  This is by design.  Out of the box, the VS Android emulator does not have an external network connection.  To resolve this, follow the instructions in the first source link to create a NEW virtual switch in HyperV, and be aware order matters.


Q:  Calling DisplayAlert from my event handler results in a hang,  How do I fix this?

A:  Change the event handler prototype to async and use await to call DisplayAlert.  The async void prototype exists specifically for event handlers.  Unlike Windows, the Xamarin GUI is designed to work only async, so conversions to sync that work in Windows - such as using the postfix .ConfigureAwait(false).GetAwaiter().GetResult() - will not work in Xamarin.

Comments