mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
485 stars 136 forks source link

Crash when using custom httpservice client #2055

Open SamYStudiO opened 1 year ago

SamYStudiO commented 1 year ago

Environment

Observed behavior and steps to reproduce

Using guide to create custom http service module with enableConfigurationfrom https://github.com/mapbox/mapbox-base-android/blob/master/MODULARIZATION.md#dependency-injection leads to app crashing at startup.

@MapboxModule(type = MapboxModuleType.CommonHttpClient, enableConfiguration = true)
class CacheableTileHttpService(private val tileProvidersRepository : TileProvidersRepository) : HttpServiceInterface {
...
}

class MainActivity : AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        Mapbox_HttpClientModuleConfiguration.moduleProvider =
            object : Mapbox_HttpClientModuleConfiguration.ModuleProvider {
                override fun createHttpClient(): HttpServiceInterface =
                    CacheableTileHttpService(viewModel.tileProvidersRepository)
            }

     super.onCreate(savedInstanceState)
    ...
}

this leads to crash MapboxInvalidModuleException(type=CommonHttpClient)

Seems PlatformHttpService.createPlatformHttpService is called before we get a chance to set moduleProvider, even setting moduleProvider from Application class will not get a chance to get called before PlatformHttpService.createPlatformHttpService

kalkun commented 1 year ago

Im also experiencing this using SDK 10.15.0.