Skip to content
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

Setting a ManageSpaceActivity causes the build to fail #9705

Closed
t4e-dev opened this issue Jan 24, 2025 · 3 comments · Fixed by #9708
Closed

Setting a ManageSpaceActivity causes the build to fail #9705

t4e-dev opened this issue Jan 24, 2025 · 3 comments · Fixed by #9708
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. Area: Mono.Android Issues with the Android API binding (Mono.Android.dll).

Comments

@t4e-dev
Copy link

t4e-dev commented Jan 24, 2025

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
@t4e-dev t4e-dev added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Jan 24, 2025
@dellis1972
Copy link
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.

@jpobst jpobst added Area: Mono.Android Issues with the Android API binding (Mono.Android.dll). and removed needs-triage Issues that need to be assigned. labels Jan 24, 2025
@jpobst
Copy link
Contributor

jpobst commented Jan 24, 2025

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

@t4e-dev
Copy link
Author

t4e-dev commented Jan 24, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. Area: Mono.Android Issues with the Android API binding (Mono.Android.dll).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants