Closed StephaneDelcroix closed 6 months ago
One way to "artificially generate" this error is to create a template Android app project and add 2 files to the Resources directory:
I confirmed the behavior with Android SDK Build Tools revision 28.0.2 and also revision 23.0.3. I also reproduced the same error in a Java Android project in Android Studio.
I also learned that once source of the hmb.png name in the original description comes from a library called Telerik.Xamarin.Android.Primitives.dll.
So the next question seems to be, does the version of Telerik.Xamarin.Android.Primitives.dll the user is building against contain both drawable-hdpi-v4\hmb.png and drawable-hdpi\hmb.png? If not, then the question might become whether the build process is somehow generating that file.
Based on the "Platform Version" information on https://developer.android.com/guide/topics/resources/providing-resources, it sounds like the library would be providing both copies explicitly. It is perhaps also worth noting that if I manually run the failing aapt.exe
command and change the --max-res-version
to 3 or lower, it succeeds because it skips both the drawable-hdpi and drawable-hdpi-v4 folders (not supported by Android API level 3).
@dellis1972, does this sound like it's on the right track?
Edit: Correct mentions of Telerik.XamarinForms.Primitives.dll to Telerik.Xamarin.Android.Primitives.dll
@brendanzagaeski not sure setting --max-res-version
that low is a good idea. It might impact other parts of the application.
Many of the android based solutions I see involve moving the file in the drawable-hdpi
directory to the other drawable-hdpi-v4
. This can probably be done via a msbuild Target
before we call the various aapt
targets (_UpdateAndroidResgen
etc).
Good point. I actually wasn't even thinking ahead yet about how to solve the problem. I was just thinking that the --max-res-version
result confirmed that aapt.exe
does seem to treat drawable-hdpi and drawable-hdpi-v4 as synonymous.
So it seems that maybe it is invalid for a library to contain the same resource in both of those directories. If that's the case, then maybe the current Xamarin.Android behavior is correct. The best way to close out this GitHub issue might be to provide a little sample MSBuild target that does what you propose to merge the drawable-hdpi and drawable-hdpi-v4 directory contents before the aapt
targets. Then any users who might come across this behavior in the future can optionally add that target to their projects while waiting for the library authors to clean up the redundant resource directories. (I can take a try at that when I get a chance if no one beats me to it.)
All that said, I also might still be missing a subtlety about what's really going on in this exact case. If the original reporter gets a chance, it might be interesting to try a couple steps to check what resources are really in the particular version of the Telerik assembly:
ildasm /output:a.il Telerik.Xamarin.Android.Primitives.dll
ildasm
extracts from the assembly, and gather the list of files that are in all of the library_project_imports\res\drawable* directories. (For example, double-click the .zip archive in Explorer to browse the contents.)With support for Classic Xamarin.Android ended May 1st, 2024, this issue is likely no longer relevant.
If this still persists in .NET 8+, please open a new issue with updated information based on net8.0-android
or greater. Please include a link to this issue for context.
originally reported here: https://github.com/xamarin/Xamarin.Forms/issues/4200
Description
App builds and runs fine on Android emulator and physical device. However building it in Azure DevOps (and deploying to App Center) doesn't work anymore. The strange part is that we don't even have a file named "hmb.png" in our solution, so this must come from a NuGet package or Xamarin Forms.
Steps to Reproduce
Basic Information
Log File