dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 531 forks source link

MonoAndroid 90 hmb.png Original is here. #2346

Closed StephaneDelcroix closed 6 months ago

StephaneDelcroix commented 6 years ago

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

  1. Start VSTS build with Xamarin.Android build step.

Basic Information

Log File

2018-10-24T13:58:24.4639459Z   Checking Android SDK Build-tools version...
2018-10-24T13:58:24.4639906Z   Selected Android SDK Build Tools Path: C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.2\
2018-10-24T13:58:24.4640333Z   Selected Android SDK Build Tools Version: 28.0.2
2018-10-24T13:58:24.4645210Z   Android SDK Build Tools Version: 28.0.2 meets minimum requirements for Vector Drawables. OK.
2018-10-24T13:58:24.4645582Z   Finished Checking Android SDK Build-tools version.
2018-10-24T13:58:25.0791152Z ##[error]##\##.Android\obj\release\MonoAndroid90\lp\26\jl\res\drawable-hdpi-v4\hmb.png(0,0): Error APT0000: Duplicate file.
2018-10-24T13:58:25.0798049Z C:\agent\_work\17\s\##\##.Android\obj\release\MonoAndroid90\lp\26\jl\res\drawable-hdpi-v4\hmb.png : error APT0000: Duplicate file. [C:\agent\_work\17\s\##\##.Android\##.Android.csproj]
2018-10-24T13:58:25.0804819Z ##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1635,2): Error APT0000: C:\agent\_work\17\s\##\##.Android\obj\release\MonoAndroid90\lp\26\jl\res\drawable-hdpi\hmb.png: Original is here. The version qualifier may be implied. "hmb.png: Original is here. The version qualifier may be implied.".
2018-10-24T13:58:25.0806385Z C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1635,2): error APT0000: C:\agent\_work\17\s\##\##.Android\obj\release\MonoAndroid90\lp\26\jl\res\drawable-hdpi\hmb.png: Original is here. The version qualifier may be implied. "hmb.png: Original is here. The version qualifier may be implied.". [C:\agent\_work\17\s\##\##.Android\##.Android.csproj]
2018-10-24T13:58:25.0874683Z Done Building Project "C:\agent\_work\17\s\##\##.Android\##.Android.csproj" (PackageForAndroid target(s)) -- FAILED.
2018-10-24T13:58:25.0891741Z 
2018-10-24T13:58:25.0893100Z Build FAILED.
brendanzagaeski commented 6 years 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

dellis1972 commented 6 years ago

@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).

brendanzagaeski commented 6 years ago

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:

  1. In a Developer Command Prompt, navigate to a directory that contains a copy of Telerik.Xamarin.Android.Primitives.dll and run:
    ildasm /output:a.il Telerik.Xamarin.Android.Primitives.dll
  2. Open the __AndroidLibraryProjects__.zip resource file that 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.)
jpobst commented 6 months ago

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.