androidmaui.net-8.0

Modify Maui .NET 8 App Icon for Android Based on Configuration , Release or Debug


I am facing the following issue within a .NET MAUI app using .NET 8: I need to display different app icons depending on whether the app is compiled in Release or Debug mode. This allows for better control when working with them.

I declare the MauiIcon in the .csproj file based on the selected build configuration:

<!-- App Icon -->
<MauiIcon Condition="'$(Configuration)' == 'RELEASE'" Include="Resources\AppIcon\appiconblack.svg" ForegroundScale="0.65" Generate="True" />

<MauiIcon Condition="'$(Configuration)' == 'DEBUG'" Include="Resources\AppIcon\appicon.svg" ForegroundScale="0.65" Generate="True" />

Up to this point, everything works well. The problem I cannot solve is how to dynamically apply the correct icon in the AndroidManifest file:

<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
</application>

I can't find a way to make the AndroidManifest dynamically load the correct app icon based on the build configuration.


Solution

  • There is no need to change anything in AndroidManifest. I have solution that should work for all platforms.

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

    This should work without any issue.

    Note: Do a Rebuild before deploying the release and debug builds.