My application can connect to several customers' base stations (servers), which each have their own baseUrl and certificate, on their local network. The app can only connect with a single one at a time, and the user can select a server through the Settings. To set the baseUrl dynamically without re-creating the Retrofit instance, I implemented an interceptor on the OkHttpClient. But changing certificate/SSLContext for an existing OkHttpClient / Retrofit provided by Hilt seems impossible without recreating a new Retrofit object with a new OkHttpClient.
I am considering using this user's second solution, which involves recreating Retrofit instances and providing them with Hilt through a RetrofitHolder wrapper class:
public class RetrofitHolder {
Retrofit retrofit;
//getter, setter
}
But I'd rather not recreate the Retrofit instances if possible. Any idea how?