8000 [XABT] Fix `ApplicationAttribute.ManageSpaceActivity` manual mapping by jpobst · Pull Request #9708 · dotnet/android · GitHub
[go: up one dir, main page]

Skip to content

Conversation

jpobst
Copy link
Contributor
@jpobst jpobst commented Jan 24, 2025

Fixes: #9705

When converting the AndroidManifest attribute mappings system in .NET 9, ApplicationAttribute.ManageSpaceActivity was not correctly mapped in the manual mapping. It needs to follow the pattern other attributes of type Type follow, like ActivityAttribute.ParentActivity:

mapping.Add (
member: "ParentActivity",
attributeName: "parentActivityName",
getter: self => self._ParentActivity,
setter: (self, value) => self._ParentActivity = (string) value,
typeof (Type)
);

With this change, the reported case in #9705 generates the proper AndroidManifest value:

<application ... android:manageSpaceActivity="crc64fe9411caa440e724.ManageSpaceActivity" ... >

@jpobst jpobst marked this pull request as ready for review January 27, 2025 17:50
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.

Should we add a test? Maybe we could build a project and assert the AndroidManifest.xml in the obj folder?

And then maybe it could assert other new attributes in the future, too.

@jonpryor jonpryor merged commit 5b0d78b into main Jan 27, 2025
58 checks passed
@jonpryor jonpryor deleted the dev/jpobst/application-attribute branch January 27, 2025 21:56
grendello added a commit that referenced this pull request Jan 28, 2025
* main:
  [ci] Remove test environment `$PATH` additions (#9712)
  [Xamarin.Android.Build.Tasks] Fix bug in the Design Time Build (#9711)
  [ci] Set `$(TreatWarningsAsErrors)` = `true` for CI builds. (#9689)
  [XABT] Fix ApplicationAttribute.ManageSpaceActivity manual mapping (#9708)
jonpryor pushed a commit that referenced this pull request Jan 30, 2025
…9708)

Fixes: #9705

Context: 3ab74db

When converting `AndroidManifest.xml` attribute mappings in 3ab74db,
`ApplicationAttribute.ManageSpaceActivity` was not correctly mapped
in the manual mapping.

The result is that if the property is used:

	[assembly: Application(ManageSpaceActivity=typeof(MyManageSpaceActivity))]

the build will fail:

	error XAGJS7007: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Type'.
	error XAGJS7007:    at Android.App.ApplicationAttribute.<>c.<AddManualMapping>b__189_3(ApplicationAttribute self, Object value) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Mono.Android/ApplicationAttribute.Partial.cs:line 47
	error XAGJS7007:    at Xamarin.Android.Manifest.ManifestDocumentElement`1.Load(T value, CustomAttribute attribute, TypeDefinitionCache cache) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocumentElement.cs:line 127
	error XAGJS7007:    at Android.App.ApplicationAttribute.FromCustomAttributeProvider(ICustomAttributeProvider provider, TypeDefinitionCache cache) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Mono.Android/ApplicationAttribute.Partial.cs:line 67
	error XAGJS7007:    at Xamarin.Android.Tasks.ManifestDocument.CreateApplicationElement(XElement manifest, String applicationClass, List`1 subclasses, TypeDefinitionCache cache) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs:line 581
	error XAGJS7007:    at Xamarin.Android.Tasks.ManifestDocument.Merge(TaskLoggingHelper log, TypeDefinitionCache cache, List`1 subclasses, String applicationClass, Boolean embed, String bundledWearApplicationName, IEnumerable`1 mergedManifestDocuments) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs:line 290
	error XAGJS7007:    at Xamarin.Android.Tasks.GenerateJavaStubs.MergeManifest(NativeCodeGenState codeGenState, Dictionary`2 userAssemblies) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs:line 363
	error XAGJS7007:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(Boolean useMarshalMethods) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs:line 270
	error XAGJS7007:    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs:line 102
	error XAGJS7007:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

`ApplicationAttribute.ManageSpaceActivity` needs to follow the
pattern other attributes of type `Type` follow, like
`ActivityAttribute.ParentActivity`:

	mapping.Add (
		member: "ParentActivity",
		attributeName: "parentActivityName",
		getter: self => self._ParentActivity,
		setter: (self, value) => self._ParentActivity = (string) value,
		typeof (Type)
	);

With this change, the reported case in #9705 generates the proper
`AndroidManifest` value:

	<application android:manageSpaceActivity="crc64fe9411caa440e724.MyManageSpaceActivity" … >
jonpryor added a commit that referenced this pull request Jan 31, 2025
…9708) (#9729)

Fixes: #9705

Context: 3ab74db

When converting `AndroidManifest.xml` attribute mappings in 3ab74db,
`ApplicationAttribute.ManageSpaceActivity` was not correctly mapped
in the manual mapping.

The result is that if the property is used:

	[assembly: Application(ManageSpaceActivity=typeof(MyManageSpaceActivity))]

the build will fail:

	error XAGJS7007: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Type'.
	error XAGJS7007:    at Android.App.ApplicationAttribute.<>c.<AddManualMapping>b__189_3(ApplicationAttribute self, Object value) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Mono.Android/ApplicationAttribute.Partial.cs:line 47
	error XAGJS7007:    at Xamarin.Android.Manifest.ManifestDocumentElement`1.Load(T value, CustomAttribute attribute, TypeDefinitionCache cache) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocumentElement.cs:line 127
	error XAGJS7007:    at Android.App.ApplicationAttribute.FromCustomAttributeProvider(ICustomAttributeProvider provider, TypeDefinitionCache cache) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Mono.Android/ApplicationAttribute.Partial.cs:line 67
	error XAGJS7007:    at Xamarin.Android.Tasks.ManifestDocument.CreateApplicationElement(XElement manifest, String applicationClass, List`1 subclasses, TypeDefinitionCache cache) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs:line 581
	error XAGJS7007:    at Xamarin.Android.Tasks.ManifestDocument.Merge(TaskLoggingHelper log, TypeDefinitionCache cache, List`1 subclasses, String applicationClass, Boolean embed, String bundledWearApplicationName, IEnumerable`1 mergedManifestDocuments) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs:line 290
	error XAGJS7007:    at Xamarin.Android.Tasks.GenerateJavaStubs.MergeManifest(NativeCodeGenState codeGenState, Dictionary`2 userAssemblies) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs:line 363
	error XAGJS7007:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(Boolean useMarshalMethods) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs:line 270
	error XAGJS7007:    at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs:line 102
	error XAGJS7007:    at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25

`ApplicationAttribute.ManageSpaceActivity` needs to follow the
pattern other attributes of type `Type` follow, like
`ActivityAttribute.ParentActivity`:

	mapping.Add (
		member: "ParentActivity",
		attributeName: "parentActivityName",
		getter: self => self._ParentActivity,
		setter: (self, value) => self._ParentActivity = (string) value,
		typeof (Type)
	);

With this change, the reported case in #9705 generates the proper
`AndroidManifest` value:

	<application android:manageSpaceActivity="crc64fe9411caa440e724.MyManageSpaceActivity" … >

Co-authored-by: Jonathan Pobst <jonathan.pobst@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Feb 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting a ManageSpaceActivity causes the build to fail

3 participants

0