Search code examples
.netxamarinxamarin.androidxamarin.essentials

error CS0234: The type or namespace name 'Platform' does not exist in the namespace 'Xamarin.Essentials'


When updating to Xamarin.Essentials v1.8.0, my Android builds fail with the following error:

error CS0234: The type or namespace name 'Platform' does not exist in the namespace 'Xamarin.Essentials' 

I checked the Xamarin.Essentials source code and confirmed that the Xamarin.Essentials.Platform class does still exist.

The only thing I've changed is to update the Xamarin.Essentials NuGet package from v1.7.7 to v1.8.0. It's not a major release, so there shouldn't be any breaking changes to my app. Is there something wrong with this build / release of Xamarin.Essentials?


Solution

  • Explanation

    In the Release Notes for Xamarin.Essentials v1.8.0, they mention that it is now targeting Android 33:

    Target MonoAndroid13.0 by @jfversluis in #2087

    Solution

    This means that to use Xamarin.Essentials, you now need to be targeting Android API 33 in your Xamarin.Android app, and there are two files we must update to fix this:

    Xamarin.Android CSPROJ

    In the csproj file for your Anrdoid app (typically named *.Droid.csproj or *.Android.csproj), update the <TargetFrameworkVersion> to v13.0:

    <TargetFrameworkVersion>v13.0</TargetFrameworkVersion>
    

    AndroidManifest.xml

    In AndroidManifest.xml (aka The Android Manifest), update android:targetSdkVersion to "33":

    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />