Erreur XA1048 de .NET pour Android

Exemples de messages

error XA1048: 'obj/Debug/net11.0-android/android/AndroidManifest.xml' does not contain an <instrumentation> element. Add an Android.App.Instrumentation subclass to the application, or set the $(AndroidInstrumentation) MSBuild property to the name of one.

Problème

L’application a été configurée pour se lancer via un Android.App.Instrumentation, soit en définissant $(AndroidUseInstrumentation) ou $(EnableMSTestRunner) à true, mais aucun élément <instrumentation> n’a été trouvé dans AndroidManifest.xml.

Cela diffère de XA1043, qui est signalé lorsque l’application ne possède ni <activity> lançable ni <instrumentation>.

Solution

Déclarez une instrumentation dans l’application :

[Instrumentation (Name = "com.companyname.myapp.MyInstrumentation")]
public class MyInstrumentation : Instrumentation
{
    protected MyInstrumentation (IntPtr handle, JniHandleOwnership ownership)
        : base (handle, ownership) { }
}

Vous pouvez également indiquer explicitement le nom de la classe à lancer avec le $(AndroidInstrumentation) propriété MSBuild, ou définissez $(AndroidUseInstrumentation) sur false pour lancer l’activité de l’application à la place.