Salesforce has announced retiring the support for original territory management https://help.salesforce.com/articleView?id=000273181&type=1 and we have our managed package using the standard salesforce Territory object which is available after enabling original Territory management. So as of today the package is dependent on Territory management and can't be installed without enabling territory management.
We are in the process of migrating from original territory management to Enterprise Territory Management.
We have customers using this package so need to make the package compatible with both old territory management and Enterprise Territory Management 2.0 till everyone is migrated to TM2.0.
As a first step want to remove the package dependency on Territory object. I am aware of using dynamic SOQL but issue is the territory object is part of released package and it has some custom fields which are being referenced throughout the code.
My question is we can't delete the Territory object from the package as it has these custom fields and need to keep it still compatible with original Territory Management for sometime till we completely migrate everyone to TM2.0
Any idea how to achieve keeping package compatible with both TM without having any hard references?
Note: This standard salesforce Territory object has custom fields as well which are being used across application.