Skip to content

Remove IsRunningOnDesktop for the Android designer #10234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 23, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 19, 2025

The Android designer has been removed from Visual Studio, but we still had code in the product supporting it. This PR removes all the desktop-specific functionality as it's no longer needed.

Changes Made

C++ Changes

  • Removed isRunningOnDesktop field from JnienvInitializeArgs struct in managed-interface.hh
  • Removed assignments to this field in monodroid-glue.cc and host.cc

C# Changes

  • Removed IsRunningOnDesktop static field from JNIEnvInit class
  • Removed initialization code and __XA_PACKAGE_NAMING_POLICY__ environment variable handling
  • Inlined conditionals in TypeManager.cs assuming desktop is always false
  • Inlined conditionals in AndroidRuntime.cs removing desktop-specific type lookups
  • Removed desktop-specific error message from SyncContext.cs

Build Changes

  • Removed __XA_PACKAGE_NAMING_POLICY__ environment variable generation from MSBuild targets
  • Updated test to no longer expect this environment variable

Key Points

  • All if (IsRunningOnDesktop) statements have been inlined/deleted assuming the condition is always false
  • The $(AndroidPackageNamingPolicy) MSBuild property remains as-is since it's still used within the codebase
  • The __XA_PACKAGE_NAMING_POLICY__ environment variable has been removed as it was only used within desktop blocks
  • Minimal changes: 9 files modified, 37 lines removed, 4 lines changed

Verification

  • Zero references to IsRunningOnDesktop remain in C# source files
  • Zero references to isRunningOnDesktop remain in C++ source files
  • Zero references to __XA_PACKAGE_NAMING_POLICY__ remain in source files
  • The compile-time is_running_on_desktop constant in monodroid-glue-internal.hh is also removed

Fixes #10233.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits June 19, 2025 22:14
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Remove IsRunningOnDesktop for the Android designer Remove IsRunningOnDesktop for the Android designer Jun 19, 2025
@Copilot Copilot AI requested a review from jonathanpeppers June 19, 2025 22:19
Copilot finished work on behalf of jonathanpeppers June 19, 2025 22:19
…est list initialization, and remove remaining is_running_on_desktop usage from C++ code

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
@Copilot Copilot AI requested a review from jonathanpeppers June 19, 2025 22:53
Copilot finished work on behalf of jonathanpeppers June 19, 2025 22:53
@jonathanpeppers jonathanpeppers marked this pull request as ready for review June 20, 2025 13:29
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.

I still see more instances of is_running_on_desktop that can be removed:

static constexpr bool is_running_on_desktop = false;

Then there are several usages in src\native\mono\monodroid\monodroid-glue.cc.

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 20, 2025

I still see more instances of is_running_on_desktop that can be removed:
https://github.com/dotnet/android/blob/c25595518479edfa6f215a82f948ae7ba7780484/src/native/mono/monodroid/monodroid-glue-int...

Fixed in 6f46321. Removed the unused is_running_on_desktop constant from the MonodroidRuntime class. There are now zero references to is_running_on_desktop in any source files.

@Copilot Copilot AI requested a review from jonathanpeppers June 20, 2025 13:54
Copilot finished work on behalf of jonathanpeppers June 20, 2025 13:54
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.

@grendello should review the changes to native code.

@@ -1299,9 +1299,7 @@ public void PackageNamingPolicy ([Values ("LowercaseMD5", "LowercaseCrc64")] str
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
var environment = b.Output.GetIntermediaryPath (Path.Combine ("__environment__.txt"));
FileAssert.Exists (environment);
var values = new List<string> {
$"__XA_PACKAGE_NAMING_POLICY__={packageNamingPolicy}"
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how this is relevant to the removal of desktop support

@@ -1758,7 +1758,6 @@ because xbuild doesn't support framework reference assemblies.

<Target Name="_GenerateEnvironmentFiles">
<ItemGroup>
<_GeneratedAndroidEnvironment Include="__XA_PACKAGE_NAMING_POLICY__=$(AndroidPackageNamingPolicy)" />
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how this is relevant to the removal of desktop support

Copy link
Member

Choose a reason for hiding this comment

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

This spot seemed to be the only place that actually reads the env var:

if (IsRunningOnDesktop) {
var packageNamingPolicy = Environment.GetEnvironmentVariable ("__XA_PACKAGE_NAMING_POLICY__");
if (Enum.TryParse (packageNamingPolicy, out PackageNamingPolicy pnp)) {
JavaNativeTypeManager.PackageNamingPolicy = pnp;
}
}

$(AndroidPackageNamingPolicy) is still left in, which embeds a value in libxamarin-app.so.

@grendello
Copy link
Contributor

The C++ changes look fine

@jonathanpeppers jonathanpeppers merged commit 3f45767 into main Jun 23, 2025
59 checks passed
@jonathanpeppers jonathanpeppers deleted the copilot/fix-10233 branch June 23, 2025 13:18
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

Error loading sessions

Retrying...

Successfully merging this pull request may close these issues.

Remove IsRunningOnDesktop for the Android designer
3 participants