Repository navigation
[Xamarin.Android.Build.Tasks] Replace GetAndroidActivityName with XmlPeek - #13493
Open
simonrozsival wants to merge 1 commit into
Open
simonrozsival wants to merge 1 commit into
simonrozsival wants to merge 1 commit into
Conversation
…Peek Add a shared `_GetAndroidLaunchableActivity` target to Xamarin.Android.Common.targets that reads the merged `$(IntermediateOutputPath)android\AndroidManifest.xml` with `<XmlPeek ProhibitDtd="true"/>` and sets `$(_AndroidLaunchableActivity)` to the first `<activity>` (falling back to the first `<activity-alias>`) in the first `<application>` whose `<intent-filter>` has the `android.intent.category.LAUNCHER` category, skipping empty names and `mono.android.__FastDevLauncher`. This mirrors `AndroidAppManifest.GetLaunchableUserActivityName()`. `_AndroidComputeRunArguments`, `RunWithLogging` and `RunTests` now depend on this target instead of calling `<GetAndroidActivityName/>`. Remove the `GetAndroidActivityName` task, its `<UsingTask/>` registrations and its unit tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new dependency causes all three device-selection test cases to fail with MSB4057 because their generated project does not define _GetAndroidLaunchableActivity.
2 open issues
What changed in this PR
Replaces the custom GetAndroidActivityName task with shared MSBuild XmlPeek queries, continuing the effort to simplify small build tasks and reduce task-hosting overhead.
Changes:
- Adds launcher discovery with activity-over-alias precedence and filtering for empty and FastDev launcher names.
- Routes run-argument computation, logging, and test launching through the shared target.
- Removes the custom task, its registrations, and its task-specific tests.
| File | Description |
|---|---|
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets |
Adds shared XPath-based launcher discovery. |
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ResolveSdksTaskTests.cs |
Removes the task’s parallel project-path tests. |
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/MultiThreadedMigrationTests.cs |
Removes the task’s launcher-selection tests and unused import. |
src/Xamarin.Android.Build.Tasks/Tasks/GetAndroidActivityName.cs |
Deletes the custom manifest-reading task. |
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Application.targets |
Uses shared discovery for run arguments and logging. |
src/Xamarin.Android.Build.Debugging.Tasks/Xamarin.Android.Common.Debugging.targets |
Uses shared discovery for RunTests and removes task registration. |
Review effort: Balanced
| <Target Name="_AndroidComputeRunArguments" | ||
| BeforeTargets="ComputeRunArguments" | ||
| DependsOnTargets="$(_AndroidComputeRunArgumentsDependsOn)"> | ||
| DependsOnTargets="$(_AndroidComputeRunArgumentsDependsOn);_GetAndroidLaunchableActivity"> |
| XmlInputPath="$(IntermediateOutputPath)android\AndroidManifest.xml" | ||
| ProhibitDtd="true" | ||
| Namespaces="<Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' />" | ||
| Query="(/manifest/application[1]/activity[intent-filter/category/@android:name='android.intent.category.LAUNCHER' and @android:name!='' and @android:name!='mono.android.__FastDevLauncher'])[1]/@android:name"> |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Context: #13481
Context: #13484
GetAndroidActivityNameis a custom MSBuild task. It loads the mergedAndroidManifest.xmlthroughAndroidAppManifest(which also needsReferenceAssemblyPathsto build a version resolver) just to return the first launchable user activity. Every custom task has to be hosted, loaded and kept multithreading-ready, and this one does nothing a single XPath query can't. This continues the effort to replace small tasks with plain MSBuild.This adds a shared
_GetAndroidLaunchableActivitytarget toXamarin.Android.Common.targets. It reads$(IntermediateOutputPath)android\AndroidManifest.xmlwith the built-in<XmlPeek ProhibitDtd="true"/>and sets$(_AndroidLaunchableActivity). It keeps the selection order ofAndroidAppManifest.GetLaunchableUserActivityName():<application>.<activity>whose<intent-filter>has theandroid.intent.category.LAUNCHERcategory.<activity-alias>.mono.android.__FastDevLauncher.The query uses the
(…)[1]/@android:nameform becauseXmlPeekevaluates its query withXPathNavigator.Select(), so a scalarstring(…)expression isn't allowed._AndroidComputeRunArguments(dotnet run),RunWithLoggingandRunTestsnow depend on this target and copy its value into$(AndroidLaunchActivity)or$(TargetTestActivity)under the same conditions as before.The target deliberately has no
Inputs/Outputs. It produces only a property, and MSBuild can't infer anXmlPeekresult for a skipped target, so the property would come back empty.Removed: the
GetAndroidActivityNametask, both of its<UsingTask/>registrations (inMicrosoft.Android.Sdk.Application.targetsandXamarin.Android.Common.Debugging.targets), and its two unit tests.Behavior differences:
LAUNCHERcategory and not theMAINaction.Testing: not built or tested locally, because of disk-space constraints for this batch; CI validates this PR. The
dotnet run/ComputeRunArguments,RunWithLoggingandRunTestspaths, including the activity-alias and instrumentation fallbacks, need CI coverage.