Including different assets for different build profiles is complicated

I am posting this to start a conversation, because I don’t even think there is a clean way to do this:

So I have multiple projects with multiple platforms and build configurations. And each one of them are using different Analytics, or, sometimes, a combination of multiple of them. So I’ve decided to make a universal adapter for all of them, which I can use as a package. I’ve put each implementation (Mixpanel, Firebase, etc.) in a corresponding folder with an assembly definition so they are not included in the build. And I made each analytics provider into a ScriptableObject (because they also need different settings fields), so I can simply drag them into a List in a settings ScriptableObject in Resources folder to register them. And an AnalyticsLoader will initialize the ones that I need for the current build configuration when the game is started.

I thought that was the cleanest way to do this, because the AnalyticsLoader doesn’t know anything about the actual analytics providers being used, right? And It won’t include any unnecessary analytics providers and their references into the build because they are not compiled when a define in their assembly definition is not set. They should just be missing references in the List.

Turns out it works, but each time I switch a build configuration, I lose references to each ScriptableObject that has a missing scripts. So in this case, the missing references are completely lost and the concept doesn’t work.

I tried switching ScriptableObjects to MonoBehaviour prefabs and reference them in a List in setting asset with another, “container” script. This container script just gives out the provider if it is compiled, and gives null when it isn’t. Now the references are there, and it works. The List is stable on every platform, but the build not only constantly complains about missing scripts, but gives errors about different serialization layout. Even though is works and can’t break.

Long story short, we can’t rely on missing scripts to not include assets in build, right? It has to be done with build preprocessors only? If so, it is inconvenient, and you need different logic in editor, because it just plays the game, and doesn’t build anything.

Can we have a “Unity” way to exclude assets from build, or to have a list of different assets for different platforms? Or am I missing something obvious?