How to use resource files in Xamarin from other NuGet packages?

Viewed 355

I need to slice an existing Xamarin app with both Android and iOS flavours into NuGet packages, with each package containing a module that brings its own UI (fragments, viewcontrollers) that shall incorporate itself into the main application's UI.

Currently I am at the point where I need to reference Android resources in one package that are defined in another NuGet package. It works fine in code, where I can just use the respective namespace of the generated Resource class, but it does not from within Android resource files, i.e. (a)xml.

Ultimately I will need to slice the iOS parts as well, but I have only reached the Android part, yet.

At least for Android, it should be possible, because it does work for Xamarin provided support libraries. But I have seen that it is a binding to an .aar file. But building an .aar file in order to bind it would defeat the purpose of building the UI in Xamarin, so this is not really a feasible workaround.

Here is an example of what does not even compile:

Resources/values/colors.xml in Project/NuGet package A:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="TextColor">#FFFFFF</color>
</resources>

Resources/values/styles.xml in Project B, referencing NuGet package A:

<resources xmlns:tools="http://schemas.android.com/tools">
  <style name="ExampleDescription">
    <item name="android:textColor">@color/TextColor</item>
  </style>
</resources>

Where A is an android library and B is an android application.

Can anyone provide any input or ideas on how to achieve the desired result? Maybe give some hints about doing it in iOS as well?

0 Answers
Related