Skip to content

[Bug]: DevTools shows only App on Android when the app uses IActivityApplicationLifetime.MainViewFactory #210

Description

@davi2td

Describe the bug

On Android, DevTools shows only App in the Elements tree when the app sets
IActivityApplicationLifetime.MainViewFactory, which is the path Avalonia 12 recommends and the one the
avalonia.xplat template generates. The TopLevel and every control are missing. This happens in the
DevTools window and through the DevTools MCP, where tree and search return []. Neither side logs an
error, the app is connected, App's properties are shown, and messages flow.

As far as we can read the 2.2.3 assembly, DiagnosticsSupport has top-level groups for
IClassicDesktopStyleApplicationLifetime, ISingleViewApplicationLifetime,
ISingleTopLevelApplicationLifetime and design time, but none for IActivityApplicationLifetime.
Android's ApplicationLifetime implements both IActivityApplicationLifetime and
ISingleViewApplicationLifetime. With only MainViewFactory set, ISingleViewApplicationLifetime.MainView
is null, so there is no root to show.

Workaround: set ISingleViewApplicationLifetime.MainView instead, which Android's lifetime turns
into the factory. The tree then shows EmbeddableControlRoot → PageNavigationHost → the app's view,
and every MCP tool works. It costs the warning "ISingleViewApplicationLifetime.MainView is not fully
supported on Android", so it isn't something to ship.

Ask: support IActivityApplicationLifetime roots in DiagnosticsSupport, so the recommended Android
path works with DevTools.

To Reproduce

  1. dotnet new avalonia.xplat -page TabbedPage -av 12.1.4, and keep the Android head.
  2. Leave the template's App.OnFrameworkInitializationCompleted as generated: it sets
    IActivityApplicationLifetime.MainViewFactory on Android.
  3. Add .WithDeveloperTools() to the Android head's AppBuilder. Allow cleartext to the DevTools host in
    network_security_config.xml. On an emulator, adb reverse tcp:29414 tcp:29414 and connect to
    127.0.0.1.
  4. Start the DevTools window, run the app, and open Elements: only App.
  5. Change step 2 to set ISingleViewApplicationLifetime.MainView instead, run again, and the full tree
    appears.

Product(s)

DevTools

Platform

Android

License Tier

Trial

Avalonia version

12.1.4 (Avalonia.Android 12.1.4)

Tool/Control Version

AvaloniaUI.DeveloperTools 2.2.3, AvaloniaUI.DiagnosticsSupport 2.2.3; .NET 11.0.100-rc.1
(net11.0-android), Android 16 emulator (API 36, x86_64), Kubuntu host

Relevant log output

DevTools MCP, the app attached:
  attach-to-app → {"connectedClient":{"runningPlatform":"android", ... "frameworkVersion":"12.1.4.0"}}
  tree   → []
  search → []
After setting ISingleViewApplicationLifetime.MainView:
  tree → [{"typeName":"EmbeddableControlRoot","children":[{"typeName":"TopLevelHost"},
          {"typeName":"PageNavigationHost","children":[{"typeName":"MainView", ...}]}]}]

Activity

  1. davi2td commented on Oct 9, 2026

    @davi2td
    Author

    A correction to the workaround above, because it breaks the app: don't set ISingleViewApplicationLifetime.MainView on Android. Android's setter turns it into a factory that returns the same instance. A new activity in a living process then draws a blank screen. Measured: press Back on the root page, then reopen the app.

    What works instead, Debug only:

    • Keep IActivityApplicationLifetime.MainViewFactory, so each activity gets a fresh root.
    • After the factory builds a root, write it into the lifetime's private _mainView field by reflection.
    activity.MainViewFactory = () =>
    {
        var root = new MainView();
    #if DEBUG
        var lifetime = Application.Current?.ApplicationLifetime;
        lifetime?.GetType().GetField("_mainView", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(lifetime, root);
    #endif
        return root;
    };

    DevTools then shows the full tree, and Back plus reopen draws normally. It still relies on a private field, so the ask stands: support IActivityApplicationLifetime roots in DiagnosticsSupport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions