Skip to content

[Bug]: Android app crashes - createPack() throwing error while downloading and app crashes on getPacks() #4230

@nv-mahesh

Description

@nv-mahesh

Mapbox Version

11.8.0

React Native Version

0.77.0

Platform

Android

@rnmapbox/maps version

10.1.45

Standalone component to reproduce

import React, { useEffect } from 'react';
import MapboxGL, {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
} from '@rnmapbox/maps';

const DownloadOfflineMap = () => {
  const RegionId = 'offline-region-1';

  const bounds = [
    [73.90, 18.45], // southwest [longitude, latitude]
    [74.05, 18.55], // northeast [longitude, latitude]
  ];

  const offlinePackOptions = {
    name: RegionId,
    styleURL: MapboxGL.StyleURL.Street,
    bounds,
    minZoom: 10,
    maxZoom: 15,
    metadata: {
      regionId: RegionId,
      downloadedAt: new Date().toISOString(),
      version: '1.0',
    },
  };

  useEffect(() => {
    createPack();
  }, []);

  const createPack = async () => {
    try {
      await MapboxGL.offlineManager.createPack(
        offlinePackOptions,
        (offlineRegion, status) =>
          console.log('Download progress:', status),
        (error) =>
          console.error('Failed to download region:', error)
      );
    } catch (error) {
      console.error('Create pack error:', error);
    }
  };

  return null; // No UI rendered
};

export default DownloadOfflineMap;

Observed behavior and steps to reproduce

For offline usage, we create and download regions using MapboxGL.offlineManager.createPack(), and then access the downloaded regions using MapboxGL.offlineManager.getPacks() to display the map and calculate routes in offline mode.
This flow works correctly on iOS — the region downloads successfully, and we can view the map offline without issues.
However, on Android, createPack() throws an error during the download process, and the offline packs are not downloaded completely. Because of this incomplete download, the app crashes when getPacks() is called while trying to open the downloaded region.

Steps to Reproduce

  • Integrate rnmapbox/maps into a React Native project
  • Configure Mapbox access token and initialize the Mapbox map
  • Define a region (bounds, zoom levels, style URL) for offline download
  • Call MapboxGL.offlineManager.createPack() to start downloading the offline region
  • Observe that the download starts but fails or throws an error on Android
  • Navigate to the screen where offline regions are loaded
  • Call MapboxGL.offlineManager.getPacks() to retrieve downloaded packs
  • App crashes on Android because the offline pack is partially downloaded

Expected behavior

  • createPack() should successfully download the offline region on Android
  • getPacks() should return only fully downloaded packs
  • Offline maps and route calculation should work without crashes

Notes / preliminary analysis

No response

Additional links and references

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🪲Something isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions