Receiving android manifiest build error on .Net7 Android app with maui essentials

41 views Asked by At

I'm upgrading an existing application from Xamarin.Android to .Net7 Android and running into issues trying to use Maui Essentials. In my .csproj file I have included these 2 lines

<UseMaui>True</UseMaui>
<UseMauiEssentials>True</UseMauiEssentials>

I also have Xamarin Essentials installed as I was using that before Maui existed. Now I get build errors related to the android manifest

/Project.Android/AndroidManifest.xml : error APT2260: resource xml/microsoft_maui_essentials_fileprovider_file_paths (aka com.app.package:xml/microsoft_maui_essentials_fileprovider_file_paths) not found. [/Project.Android.csproj]

/Project.Android/AndroidManifest.xml : error APT2260: resource xml/xamarin_essentials_fileprovider_file_paths (aka com.app.package:xml/xamarin_essentials_fileprovider_file_paths) not found. [/Project.Android.csproj]

There seem to be a few others referencing "xml/library_file_paths" and "integer/google_player_services_version". I'm not sure if it has anything to do with Maui but this is the first time noticing the issue. It may be more of a .Net7 thing. Currently working in Visual Studio Code on a mac if it matters.

1

There are 1 answers

0
Sean He-MSFT On

No action is required to use Xamarin.Essentials in .NET MAUI app, other than removing references to the Xamarin.Essentials namespace, because .NET MAUI already includes the functionality from Xamarin.Essentials.

So you can try to first remove the Xamarin.Essentials NuGet package from your .NET Android app.

Then initialize the "essentials" functionality by calling the Platform.Init method in MainActivity class:

using Android.Content.PM;
using Android.Runtime;
using Microsoft.Maui.ApplicationModel;

namespace MyAndroidApp;

[Activity(Label = "@string/app_name", MainLauncher = true)]
public class MainActivity : Activity
{
    protected override async void OnCreate(Bundle? savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        Platform.Init(this, savedInstanceState);
        // ...
    }
}

For more details, you can refer to Migrate Xamarin.Essentials code in .NET Android apps