.NET for Android 错误 XA1042

示例消息

error XA1042: The <instrumentation> element in 'obj/Debug/net11.0-android/android/AndroidManifest.xml' is missing the android:name attribute.

Issue

dotnet run 通过其 <activity> 元素启动一个没有可启动类的应用,但在 <instrumentation> 中找到的 AndroidManifest.xml 元素没有 android:name 属性,因此没有可启动的类。

解决方案

为 <instrumentation> 元素命名。 如果它在你手写的 AndroidManifest.xml 中声明,请添加该属性:

<instrumentation android:name="com.companyname.myapp.MyInstrumentation" />

如果该元素由 Android.App.Instrumentation 子类生成,请在 [Instrumentation] 属性上设置 Name 属性:

[Instrumentation (Name = "com.companyname.myapp.MyInstrumentation")]
public class MyInstrumentation : Instrumentation
{
}

或者,将 $(AndroidInstrumentation) MSBuild 属性设置为要启动的类名。