適用於 Android 的 .NET 錯誤 XA1048

範例訊息

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.

Issue

應用程式選擇透過 Android.App.Instrumentation 啟動,無論是藉由設定 $(AndroidUseInstrumentation) 或 $(EnableMSTestRunner) 到 true,但在 AndroidManifest.xml 中找不到任何 <instrumentation> 元素。

這與 XA1043 不同;當應用程式既沒有可啟動的 <activity>,也沒有 <instrumentation> 時,才會回報後者。

解決方案

在應用程式中宣告一種儀器:

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

你也可以使用以下方式明確指定要啟動的類別 $(AndroidInstrumentation) MSBuild 屬性,或將 $(AndroidUseInstrumentation) 設為 false,改為啟動應用程式的活動。