Skip to content

Fix AndroidDeviceUserId not passed to am start on debug/run#10861

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-android-device-user-id
Open

Fix AndroidDeviceUserId not passed to am start on debug/run#10861
Copilot wants to merge 3 commits intomainfrom
copilot/fix-android-device-user-id

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

  • Fix StartAndroidActivity target in Xamarin.Android.Application.targets to include --user $(AndroidDeviceUserId) when set
  • Fix _AndroidComputeRunArguments target in Microsoft.Android.Sdk.Application.targets to include --user for both Microsoft.Android.Run and direct adb paths
  • Fix RunWithLogging target in Microsoft.Android.Sdk.Application.targets to include --user
  • Add --user command-line option to Microsoft.Android.Run/Program.cs
  • Pass --user to am force-stop in StopApp() for consistent behavior on work profiles
  • Add MSBuildDeviceIntegration test to verify AndroidDeviceUserId is passed to am start command
  • Run code review and security checks
Original prompt

This section details on the original issue you should resolve

<issue_title>Since .NET10 migration the element AndroidDeviceUserId is not respected on debug</issue_title>
<issue_description>This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work]
We migrated our solution from .NET9 to .NET10.
On Android we are using devices with Android Enterprise profiles.
We deploy and debug in the Profile User 10.
The element AndroidDeviceUserId in our main csproj file is being respected on deployment.
But when we hit "Debug" the command am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n ".****..****/crc643aba18955c58aa24.CoordinatorActivity" is generated and the entry --user 10 is missing.
This was different in .NET9


Original Comments

Feedback Bot on 2/20/2026, 10:44 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

<agent_instructions>Make sure we write a tests in MSBuildDeviceIntegration that checks the user id comes through</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…rt commands

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix AndroidDeviceUserId issue in debug after .NET10 migration Fix AndroidDeviceUserId not passed to am start on debug/run Feb 26, 2026
@jonathanpeppers jonathanpeppers marked this pull request as ready for review February 26, 2026 19:19
Copilot AI review requested due to automatic review settings February 26, 2026 19:19
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test passes:

Image

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes launching on non-primary Android users (e.g., Android Enterprise work profiles) by propagating AndroidDeviceUserId into all relevant am start invocations across legacy and SDK-style run paths.

Changes:

  • Add conditional --user $(AndroidDeviceUserId) to StartAndroidActivity and other MSBuild launch paths (including dotnet run and logging-based runs).
  • Add a new --user CLI option to Microsoft.Android.Run and forward it to am start.
  • Add a device integration test asserting --user appears in the generated am start command.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs Adds an integration test intended to verify --user is included in am start.
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Application.targets Updates StartAndroidActivity to include --user when AndroidDeviceUserId is set.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Application.targets Threads --user through all three launch paths (tool-based run, direct adb fallback, and RunWithLogging).
src/Microsoft.Android.Run/Program.cs Adds --user option and appends it to am start arguments.

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Since .NET10 migration the element AndroidDeviceUserId is not respected on debug

3 participants