Search code examples
androidxamarinxamarin.formsffimageloading

Xamarin - Items not loading or missing from 'Resources' folder in Release only


I have developed a Xamarin.Forms application using Visual Studio 2019. This targets iOS and Android. I have currently being developing in Debug mode.

The application contains many svg images which are loaded using the FFImageLoading.Svg.Forms plugin as follows:

SvgCachedImage imageSearch = new SvgCachedImage
{
    Source = "resource://AppName.Resources.add_red.svg",
    WidthRequest = 25,
};

These are all saved under the AppName/Resources folder. Each item's properties are as follows:

resource properties

This works perfectly in the Android simulator, on an Android Phone and also on an iPhone simulator, all in Debug mode.

I have now tried to create an Android APK in Release mode.

The APK installs onto the Android phone. The application loads without any error, but all of the items in the Resources folder are not displayed? All other elements are displayed.

I have tried:

  • Code shrinker: None
  • Linking: Sdk and User Assemblies

Any ideas or suggestions on what could be causing this?

Versions:

  • Xamarin.Essentials (1.3.1)
  • Xamarin.Forms (4.3.0.819712-pre2)
  • Xamarin.FFImageLoading.Svg.Forms (2.4.11.982)

Solution

  • After a lot of rummaging around and testing lots of different settings, the solution was to create a completely new solution. I was not able to find a setting that was causing the problem:

    1. Create a new Xamarin Forms project.
    2. Copy all the original .cs and .xaml files into the new project folder. Don't copy the .csproj files.
    3. Add all the resources back into the corresponding folders.

    The application was then first tested in Debug mode, then in a Release emulator. All SVG graphics loaded correctly.

    Finally, an Archive and APK was made and tested on an Android phone, all worked perfectly and as expected.

    I have absolutely no idea of the actual cause of this problem, but this workaround definitely saved me.