Skip to content

Setting a ManageSpaceActivity causes the build to fail #9705

Description

@t4e-dev

Android framework version

net9.0-android

Affected platform version

VS 2022

Description

ManageSpaceActivity not working since update to .NET9

[assembly: Application(
#if DEBUG
    Debuggable = true
#endif
  , ManageSpaceActivity = typeof(ManageSpaceActivity)
    )
 ]
´´´

this causes the build to fail:

5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): error XAGJS7007: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Type'.
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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
5>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\35.0.24\tools\Xamarin.Android.Common.targets(1488,3): 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


### Steps to Reproduce

- Add an activity to the solution
- Set ManageSpaceActivity on Application attribute
- Build

### Did you find any workaround?

No.
Wiring the fully qualified name in Android Manifest directly did not solve the issue. 
The activity was not available in the Android application menu

### Relevant log output

```shell

Activity

  1. added
    Area: App+Library BuildIssues when building Library projects or Application projects.
    needs-triageIssues that need to be assigned.
    on Jan 24, 2025
  2. dellis1972 commented on Jan 24, 2025

    @dellis1972
    Contributor

    If you want to use the fully qualified name in the AndroidManifest.xml you will need to use the "mangled" name unless you specify a Register attribute on your ManageSpaceActivity.

    If you look in your obj/Debug/netX.0-android/android/AndroidManifest.xml which is the final manifest, you can see the "managled" versions of the types. They will be something like android:name="crc64fdd50140bdf7fe6b.ManageSpaceActivity".

    The crc64fdd50140bdf7fe6b value is the encoded namespace of the type it will be a different value for your specific application. This is done to make sure we do not go over the Path limits on windows as java code has to be placed in subfolders and we quickly run out of path characters.

    If you use the Register attribute you can provide the string type you want to use eg.

    [Activity(Theme = "@style/Maui.SplashTheme")]
    [Register ("com.foo.bar.ManageSpaceActivity")]
    public class ManageSpaceActivity: Activity {
    }

    As for the bug, it looks like we are defining the Type on the Attribute, but want to resolve that to a string for the xml file.

  3. added
    Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).
    and removed
    needs-triageIssues that need to be assigned.
    on Jan 24, 2025
  4. jpobst commented on Jan 24, 2025

    @jpobst
    Contributor

    Heh, I guess I touched this last. I'll look and see if I broke something. 😆

  5. t4e-dev commented on Jan 24, 2025

    @t4e-dev
    Author

    Thanks :-)
    By the way:
    Using Register attribute and putting the name directly into the manifest fixed it for us.
    Thanks for that too :-)

  6. locked and limited conversation to collaborators on Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.Area: Mono.AndroidIssues with the Android API binding (Mono.Android.dll).

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions