Repository navigation
[NativeAOT] [MetaData] on Application class missing from manifest #13175
Description
Android framework version
net11.0-android (Preview)
Affected platform version
.NET SDK 11.0.100-rc.2.26504.105
Description
While testing NativeAOT, I noticed that [MetaData] attributes on my Application class aren't included in the generated AndroidManifest.xml. The same attributes work with the default CoreCLR configuration.
This caused Google Maps to crash with “API key not found”, even though the key is declared on the Application class.
I've attached a small repro without any Google Maps dependency. Both Value and Resource metadata are affected. Metadata on an Activity, at assembly scope, or written directly in AndroidManifest.xml works.
I also tried CoreCLR with AndroidTypeMapImplementation=trimmable, which has the same problem.
It looks like UpdateApplicationElement copies the application properties but doesn't write component.MetaData:
android/src/Microsoft.Android.Sdk.TrimmableTypeMap/Generator/ComponentElementBuilder.cs
Lines 238 to 249 in 801f9ec
| internal static void UpdateApplicationElement (XElement app, JavaPeerInfo peer, int targetSdkVersion = 0) | |
| { | |
| string jniName = JniSignatureHelper.JniNameToJavaBinaryName (peer.JavaName); | |
| app.SetAttributeValue (AttName, jniName); | |
| var component = peer.ComponentAttribute; | |
| if (component is null) { | |
| return; | |
| } | |
| PropertyMapper.ApplyMappings (app, component.Properties, PropertyMapper.ApplicationElementMappings, targetSdkVersion: targetSdkVersion); | |
| } | |
Steps to Reproduce
- Extract the ManifestMetadataRepro.zip into two separate folders.
- In the first folder, run:
dotnet publish -c Release -r android-arm64 -p:PublishAot=false
- In the second folder, run:
dotnet publish -c Release -r android-arm64 -p:PublishAot=true
- Compare
obj/Release/net11.0-android/android-arm64/android/AndroidManifest.xmlfrom both folders.
The CoreCLR manifest contains repro.application.value and repro.application.resource. Both are missing from the NativeAOT manifest, although both builds succeed.
Did you find any workaround?
Moving the attributes to assembly scope works:
[assembly: MetaData("repro.application.value", Value = "application-present")]
[assembly: MetaData("repro.application.resource", Resource = "@string/repro_value")]
Declaring the entries directly in AndroidManifest.xml also works.
Activity
[TrimmableTypeMap] Preserve manifest attributes