How is the package manager handled in Cloud Build?

Unity 2019.4.8, Windows 10

The issue I encountered:

Some packages (not Unity official) have strange behaviour, that will result some conflict with one another when build for Android. Like manifest conflict, or some aar file conflict. That’s why during build, some of the packages needs to be removed from compile.

Since there are no way to automatically exclude package when build for one “target I defined”, I have to use something like this exclude and include:

Request request = Client.Remove(packageName);
while (!request.IsCompleted)
{
}
Request request = Client.Add(packageName);
while (!request.IsCompleted)
{
}

However, this will result an issue in new XR Management. After package is changed, for example I switched from SteamVR to Oculus, I remove Steam, and add Oculus, the XR Management seems sick, and doesn’t let me choose Oculus as a Plug-in Providers. When I click Oculus, editor will load for a moment, and nothing happens, without any log output. This issue still persist, when I restart Unity, and it can ONLY be solved when I delete “obj” and “Library” folder in project.

And I checked how Client class should be used, I noticed that it uses EditorApplication.update for an editor tick, and I believe this is is solution I need. However, from what I understand, Cloud Build doesn’t allow editor update or Coroutine when building in cloud.

So my question is, how on earth can we do dynamic package inclusion and exclusion during cloud build?

Might be best to ask here: Unity Engine - Unity Discussions

Or perhaps in the cloud build support forum?

I have a solution and answered my own questions there: