Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set Maui icon to a PNG file [Android] #27061

Closed
Mark-NC001 opened this issue Jan 10, 2025 · 7 comments
Closed

Unable to set Maui icon to a PNG file [Android] #27061

Mark-NC001 opened this issue Jan 10, 2025 · 7 comments
Labels
area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@Mark-NC001
Copy link

Description

I have a Maui project that targets Android. I am not using SVG files, but when I try and set my MauiIcon to a PNG file, I get the following errors:

APT2067 failed processing manifest
APT2260 resource mipmap/appicon (aka uk.police.norfolk.forceformsdebug:mipmap/appicon) not found.

Steps to Reproduce

Open the linked repository.
Notice in the proj file, I have the following MauiIcon and MauiRoundIcons set:

		<!-- App Icon -->
		<MauiIcon Include="Resources\AppIcon\location_darkblue.png" />
		<MauiRoundIcon Include="Resources\AppIcon\location_darkblue.png" />

Notice that I have removed the bit:
android:roundIcon="@mipmap/appicon_round"
in the AndroidManifest.xml.

Link to public reproduction project repository

https://github.com/Mark-NC001/TestMauiAndroidIcon

Version with bug

9.0.22 SR2.2

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

No response

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

@Mark-NC001 Mark-NC001 added the t/bug Something isn't working label Jan 10, 2025
@jfversluis
Copy link
Member

You probably want to remove this section and try again. Also, I don't think MauiRoundIcon is something that exists?

@jfversluis jfversluis added area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer platform/android 🤖 s/needs-info Issue needs more info from the author labels Jan 10, 2025
@Mark-NC001
Copy link
Author

@jfversluis Oops, thanks for pointing that Remove part out! I've updated my repository. It still gives the same error though, and I've also removed the MauiRoundIcon bit too.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jan 10, 2025
@bhavanesh2001
Copy link

bhavanesh2001 commented Jan 10, 2025

The android:icon set in your AndroidManifest.xml should match with name you defined MauiIcon

As @jfversluis was mentioning there is no MauiRoundIcon. But you can set the round icon in android manifest.

First define your icon's in csproj correctly

<MauiIcon Include="Resources\AppIcon\location_darkblue.png" />

Then update the AndroidManifest

<application android:allowBackup="true" 
                     android:icon="@mipmap/location_darkblue" 
                     android:roundIcon="@mipmap/location_darkblue_round"
                     android:supportsRtl="true">
</application>

Clean and Rebuild.

Everything was mentioned in documentation here.

@jfversluis
Copy link
Member

Oh good catch @bhavanesh2001 thank you! That indeed should be it :) Let us know if that works!

@jfversluis jfversluis added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Jan 11, 2025
@Mark-NC001
Copy link
Author

Mark-NC001 commented Jan 13, 2025

@bhavanesh2001 Thanks for your input. I thought that "@mipmap/appicon" was in effect a placeholder and would be replaced with the name of the first MauiIcon declared in the project file? (and similar for the roundIcon).

In my actual app (as opposed to the demo in the repository) I have multiple MauiIcons, using Condition="'$(Configuration)'=='Testing'" etc in the project file for different configurations as I have different icons for Release, Testing and Training. I don't believe I can do similar in the AndroidManifest.xml file?

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jan 13, 2025
@bhavanesh2001
Copy link

bhavanesh2001 commented Jan 13, 2025

replaced with the name of the first MauiIcon declared in the project file?

@Mark-NC001 I don' t think this is the case ... But I understand the need of having different Icon's based upon Configuration.

I will suggest a simple solution which doesn't include changing you AndroidManifest every time.

  1. Create multiple Sub Folders in you AppIcon Folder, Debug, Release , Test etc...
  2. Now add your app icon file's to respective folders. The name of the all files should be same. Ex: location_darkblue.png
  3. Now in csproj file you can specify the icon depending upon configuration, like below
<MauiIcon Condition="'$(Configuration)' == 'RELEASE'" Include="Resources\AppIcon\Release\location_darkblue.png" ForegroundScale="0.65" Generate="True" />
<MauiIcon Condition="'$(Configuration)' == 'DEBUG'" Include="Resources\AppIcon\Debug\location_darkblue.png" ForegroundScale="0.65" Generate="True" />
<MauiIcon Condition="'$(Configuration)' == 'TEST'" Include="Resources\AppIcon\Test\location_darkblue.png" ForegroundScale="0.65" Generate="True" />

Clean and Rebuild.
This should work without any issue.

@Mark-NC001
Copy link
Author

@bhavanesh2001 thank you for your suggestion, I've done it that way and it works well! I think I probably made an incorrect assumption as there was no file extension in the android manifest for appicon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants