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 528 forks source link

Mipmap Icon Error #2769

Closed npagare closed 5 years ago

npagare commented 5 years ago

Steps to Reproduce

  1. Create a new Xamarin.Forms based Android App
  2. Create a set of adaptive icons using Image Asset Studio that comes with Android Studio. This process created a set of 6 mipmap folders including mipmap-anydpi-26 and 5 for hdpi to xxxhdpi resoutions.
  3. If your Xamarin Forms based Android project doesn't have those mipmap folders then copy those folders as-is under Resources directory (that was my case originally when I got this error) OR if those folders exist then copy corresponding icons related files from and to the respective folders.
  4. Updated mainactivity class, AndroidManifest.xml tag with mipmap based values for icon and roundicon.

It will result the compilation failing indicating with the error - "error APT0000: No resource found that matches the given name (at 'drawable' with value '@mipmap/{iconname_background} | same for foreground layer.

Your help in addressing this error will be appreciated.

Repro solution - AdaptiveIconsAndroid.zip

Expected Behavior

Xamarin Forms - Android App to compile successfully and render adaptive icon depending on the target device and its resolution.

Actual Behavior

Build fails with the errors - 1>{User Directory}\source\repos\AdaptiveIconsAndroid\AdaptiveIconsAndroid\AdaptiveIconsAndroid.Android\Resources\mipmap-anydpi-v26\AdaptiveIcon.xml(2): error APT0000: No resource found that matches the given name (at 'drawable' with value '@mipmap/AdaptiveIcon_background'). 1>{User Directory}\source\repos\AdaptiveIconsAndroid\AdaptiveIconsAndroid\AdaptiveIconsAndroid.Android\Resources\mipmap-anydpi-v26\AdaptiveIcon.xml(2): error APT0000: No resource found that matches the given name (at 'drawable' with value '@mipmap/AdaptiveIcon_foreground'). 1>{User Directory}\source\repos\AdaptiveIconsAndroid\AdaptiveIconsAndroid\AdaptiveIconsAndroid.Android\Resources\mipmap-anydpi-v26\AdaptiveIcon_round.xml(2): error APT0000: No resource found that matches the given name (at 'drawable' with value '@mipmap/AdaptiveIcon_background'). 1>{User Directory}\source\repos\AdaptiveIconsAndroid\AdaptiveIconsAndroid\AdaptiveIconsAndroid.Android\Resources\mipmap-anydpi-v26\AdaptiveIcon_round.xml(2): error APT0000: No resource found that matches the given name (at 'drawable' with value '@mipmap/AdaptiveIcon_foreground').

Version Information

Log File

BuildOutput.log.txt

Redth commented 5 years ago

The root of the problem is uppercase characters in resource names.

Even though your resources are named AdaptiveIcon_*, they really get renamed adaptiveicon_* while building your app, so your AdaptiveIcon.xml and AdaptiveIcon_round.xml need to be updated to use adaptiveicon_foreground and adaptiveicon_background:

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@mipmap/adaptiveicon_background"/>
    <foreground android:drawable="@mipmap/adaptiveicon_foreground"/>
</adaptive-icon>

Don't forget to change your [Activity...] attribute in MainActivity as well to point to: Icon = "@mipmap/adaptiveicon".

It might be least confusing to rename everything (including the resource files themselves) to lowercase.

@dellis1972 @jonathanpeppers not sure what the expectation here is, but should we be fixing up the manifest as well as xml resources to lowercase resources they reference?

npagare commented 5 years ago

Hi @Redth , thank you for looking into this and helping me out.

It seems that assets generated out of Image Asset Manager has to be named in the lowercase. But, the original assets could be named in a mixed case.

image

Attaching a copy of the Android Studio build log that provides precise error description around this issue. I would appreciate if Xamarin.Android build process either bubbles up that error description or have a similar meaningful explanation.

AndroidStudioBuildError.log.txt

dellis1972 commented 5 years ago

This problem is in our ConvertResourcesCases task. It is not lowercasing the values in the adaptiveicon.xml in the mipmap folders. So we end up with

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"><background android:drawable="@mipmap/AdaptiveIcon_background" /><foreground android:drawable="@mipmap/AdaptiveIcon_foreground" /></adaptive-icon>

which is incorrect. I'll add a unit test for this and then fix up the task to handle these files.

dellis1972 commented 5 years ago

Fix is up https://github.com/xamarin/xamarin-android/pull/2785