dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

APT2259 Incompatible with Attribute Resource (attr) Reference is not Verbose #9755

Open DamianSuess opened 2 years ago

DamianSuess commented 2 years ago

Description

Error, APT2259, does not provide the correct information as to where or what the error is that needs to be fixed. The error message incorrectly states that the issue is in the AndroidManifest.xml file when it is really in a class.

APT2259 '@xml=app_widget' is incompatible with attribute resource (attr) reference.

The actual issue was caused by a typo in my AppWidgetProvider class, "MokaWidget.cs", where I incorrectly used an equal sign, "@xml=app_widget" instead of a forward slash, "@xml/app_widget".

  ...
  [MetaData("android.appwidget.provider", Resource = "@xml/app_widget")]
  public class MokaWidget : AppWidgetProvider
  {
     ...

To reproduce this error, you can use the simple GitHub repo, https://github.com/DamianSuess/MokaWidget, and reinsert the typo. The repo's was created for a tutorial to showcase how to create Android Widgets using .NET MAUI.

Error List

Severity    Code    Description Project File    Line    Suppression State
Error   APT2259 '@xml=app_widget' is incompatible with attribute resource (attr) reference.

This error is likely caused by an issue with the AndroidManifest.xml file or an Android manifest generation attribute in a source code file.    SuessLabs.MokaWidget    C:\xxxx\CoffeeWidget\source\Platforms\Android\AndroidManifest.xml   1   

Output - Build

Rebuild started...
1>------ Rebuild All started: Project: SuessLabs.MokaWidget, Configuration: Debug Any CPU ------
Restored C:\xxxx\CoffeeWidget\source\SuessLabs.MokaWidget.csproj (in 246 ms).
1>SuessLabs.MokaWidget -> C:\xxxx\CoffeeWidget\source\bin\Debug\net6.0-android\SuessLabs.MokaWidget.dll
1>C:\xxxx\CoffeeWidget\source\Platforms\Android\AndroidManifest.xml : error APT2259: '@xml=app_widget' is incompatible with attribute resource (attr) reference.
1>C:\xxxx\CoffeeWidget\source\Platforms\Android\AndroidManifest.xml : error APT2259: 
1>C:\xxxx\CoffeeWidget\source\Platforms\Android\AndroidManifest.xml : error APT2259: This error is likely caused by an issue with the AndroidManifest.xml file or an Android manifest generation attribute in a source code file.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.448\tools\Xamarin.Android.Aapt2.targets(212,3): error APT2067: failed processing manifest.
1>Done building project "SuessLabs.MokaWidget.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Steps to Reproduce

Note, that the steps below pertain to Platforms\Android only, all other platforms are not being used.

  1. Create a base .NET MAUI project
  2. Create Android AppWidgetProvider inherited class which points to app_widget.xml file
    • Sample: [MetaData("android.appwidget.provider", Resource = "@xml=app_widget")]
    • NOTE: The use of the = (equal) sign in @xml=app_widget instead of, @xml/app_widget
  3. Created Widget.axml file
  4. Added resources
  5. Build

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12

Did you find any workaround?

No response

Relevant log output

No response

DamianSuess commented 2 years ago

Updated the details to clearly state the cause of the error and how to reproduce it.

PureWeen commented 2 years ago

@jonathanpeppers thoughts?

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

jonathanpeppers commented 2 years ago

The error message:

Error   APT2259 '@xml=app_widget' is incompatible with attribute resource (attr) reference.

Came directly from the aapt2 tool from the Android SDK, we added this additional text from the .NET for Android workload:

This error is likely caused by an issue with the AndroidManifest.xml file or an Android manifest generation attribute in a source code file.    SuessLabs.MokaWidget    C:\xxxx\CoffeeWidget\source\Platforms\Android\AndroidManifest.xml   1   

Can you give some more detail on what we should actually change here? I think we have to surface Android SDK errors exactly as they are given.