I have created a multi-target project that targets netstandard, xamarin.ios and monodroid10. Everything works fine with Debug and Release modes for both platforms when I build it myself. However, when our pipeline builds in Release mode, custom renderers in Android app is ignored, and the controls are using the default renderers.
What I'm wondering is that are there any factors in MSBuild that might cause renderers to be not compiled or ignored at runtime due to the build configuration?
Unfortunately, I can't share any small project to reproduce or the build log, but I might share some info in the multi-target solution:
- AssemblyInfo folder has ExportRenderer imports for all platforms. Also, each custom renderer has ExportRenderer implemented.
- Static initializer for the library is called before Xamarin.Forms.Init() call.
- Linker in the application is set to SDK Assemblies only (
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
) - Linker is ignoring the multi-target assembly (
<AndroidLinkSkip>MultiTargetAssemblyName</AndroidLinkSkip>
) - Controls are using default Xamarin renderers for their corresponding base classes. There is no crash, just unexpected UX behavior due to the missing renderers.
- Library is working completely fine in iOS, both debug/release modes and when CI builds it. Issue is only happening on Android side.
- Multitarget project is built with MSBuild.Sdk.Extras/3.0.44 SDK.
Further investigation showed that Android project is using the netstandard2.0 version of the multi-target dll during msbuild.
and I started to see this missing namespace errors
/Users/runner/work/1/s/Test.Test.Mobile/Test.Test.Mobile.Android/Renderers/ControlLibrary/LibraryButtonRenderer.cs(3,38): error CS0234: The type or namespace name 'Android' does not exist in the namespace 'Test.Test.Mobile.Controls' (are you missing an assembly reference?) [/Users/runner/work/1/s/Test.Test.Mobile/Test.Test.Mobile.Android/Test.Test.Mobile.Android.csproj]
Why on earth build agent takes the one for the shared library and uses in MonoDroid10.0 project?