Search code examples
androidmapbox-androidmapbox-studio

Android Mapbox SDK loading style failed: "HTTP status code 404"


couldn't find an answer for this problem in SO and github.

I'm getting loading style failed: "HTTP status code 404 in onDidFailLoadingMap listener when I'm trying to load style with a URI i got from Mapbox Studio.

I have double checked the URI and the token in my code and and it all works just fine in IOS.

the code is similar to the code in Mapbox examples https://docs.mapbox.com/android/maps/examples/use-a-mapbox-studio-style/

also it works just fine if i put one of their style URIs.

        Mapbox.getInstance(this, getResources().getString(R.string.my_studio_token));
        mapView.onCreate(savedInstanceState);

        mapView.addOnDidFailLoadingMapListener(new MapView.OnDidFailLoadingMapListener() {
            @Override
            public void onDidFailLoadingMap(String errorMessage) {
                Log.i("style_load", errorMessage); //gets here after failure
            }
        });

        mapView.getMapAsync(mapboxMap -> {
            mapboxMap.setStyle(new Style.Builder().fromUri(getResources().getString(R.string.travily_style_uri)), 
                               style -> Log.i("style_load", style.toString()));

as result I'm getting an empty screen with no map.

i'd be glad to add any code snippets if needed.

thanks :)


Solution

  • After hours of debugs I finally figured out where the problem was.

    I had Mapbox.getInstance in my Application file (which is fired up before the first activity) that somehow made the later Mapbox.getInstance in the activity file irrelevant.

    Once i changed the token in the first Mapbox.getInstance it worked.

    Probably the reason that it worked for uri from mapbox examples is because those uri are public and do not require a specific token.

    Hope it will help someone with the same issue.