.NET for Android のエラー XA1043

メッセージの例

error XA1043: Could not determine what to launch: 'obj/Debug/net11.0-android/android/AndroidManifest.xml' does not contain a launchable <activity> or an <instrumentation> element. Set the $(AndroidLaunchActivity) or $(AndroidInstrumentation) MSBuild property to specify one.

Issue

dotnet run には、デバイスで起動するものが必要です。 AndroidManifest.xmlで起動可能な<activity>を検索し、ベンチマーク ホストなどのユーザー インターフェイスがないアプリの<instrumentation>要素にフォールバックします。 どちらも見つかりませんでした。

ソリューション

MAIN / LAUNCHER インテント フィルターを使用してアクティビティを宣言します。

[Activity (MainLauncher = true)]
public class MainActivity : Activity
{
}

または、アクティビティがないアプリの場合は、インストルメンテーションを宣言します。

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

を使用して、起動するクラスを明示的に指定することもできます。 $(AndroidLaunchActivity) または $(AndroidInstrumentation) MSBuild プロパティ。