.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 透過其 <instrumentation> 元素啟動沒有可啟動的 <activity> 的應用程式,但在 AndroidManifest.xml 中找到的 <instrumentation> 元素沒有 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 屬性設為要啟動的類別名稱。