Skip to content

fix(android): load require()'d 3D models in release builds - #4434

Merged
mfazekas merged 1 commit into
mainfrom
fix/android-glb-require-release
Nov 5, 2026
Merged

mfazekas merged 1 commit into
mainfrom
fix/android-glb-require-release

Conversation

@mfazekas

@mfazekas mfazekas commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #4433

In Android Release builds React Native ships non-image assets in res/raw, so Image.resolveAssetSource(require('./car.glb')) returns just a resource name like src_assets_sportcar. LocationPuck (model.uri) and Models passed that name to Mapbox, which fails with Unknown model file type: src_assets_sportcar. Bare names that match a raw resource are now copied once per process to cacheDir/rnmbx-models/<name>.glb (or .gltf when the file lacks the glb magic) and passed as a file:// URL. URLs with a scheme (Metro http:// in Debug, asset://, https://) are passed through as before. iOS is not affected, its resolved asset URLs already point into the bundle with the extension.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Screenshot OR Video

Reproducer below on an Android 14 arm64 emulator (Pixel 6), Release build, each stage held 8 s:

stage main this PR
LocationPuck require('…glb') no model, E/Mapbox [maps-core]: Unknown model file type: src_assets_sportcar model renders
LocationPuck asset://sportcar.glb renders renders
LocationPuck 2D (no model) renders renders
Models + ModelLayer require('…glb') no model, same error model renders
Models + ModelLayer asset://sportcar.glb renders renders

Debug build with Metro on this PR: both require stages render, no model errors. yarn lint, yarn type:check and yarn unittest pass.

Component to reproduce the issue you're fixing

Needs sportcar.glb (from example/src/assets) next to it, and a copy in android/app/src/main/assets/ for the asset:// stages. Build in Release.

import React, { useEffect, useState } from 'react';
import { Text, View } from 'react-native';
import {
  Camera,
  LocationPuck,
  MapView,
  ModelLayer,
  Models,
  ShapeSource,
} from '@rnmapbox/maps';

const center = [-71.1, 42.34];
const point = { type: 'Point', coordinates: center };
const stages = [
  { name: 'puck-require', model: { uri: require('./sportcar.glb'), scale: [40, 40, 40] } },
  { name: 'puck-asset-url', model: { uri: 'asset://sportcar.glb', scale: [40, 40, 40] } },
  { name: 'puck-2d' },
  { name: 'modellayer-require', layer: { car: require('./sportcar.glb') } },
  { name: 'modellayer-asset-url', layer: { car: 'asset://sportcar.glb' } },
];

export default function GlbRepro() {
  const [i, setI] = useState(0);
  useEffect(() => {
    if (i >= stages.length) return;
    const t = setTimeout(() => setI(i + 1), 8000);
    return () => clearTimeout(t);
  }, [i]);
  const stage = stages[i] ?? stages[0];
  return (
    <View style={{ flex: 1 }}>
      <MapView style={{ flex: 1 }}>
        <Camera centerCoordinate={center} zoomLevel={18} pitch={50} animationDuration={0} />
        {stage.layer ? (
          <>
            <Models models={stage.layer} />
            <ShapeSource id="glb-src" shape={point}>
              <ModelLayer id="glb-layer" style={{ modelId: 'car', modelScale: [40, 40, 40] }} />
            </ShapeSource>
          </>
        ) : (
          <LocationPuck model={stage.model} />
        )}
      </MapView>
      <Text style={{ position: 'absolute', top: 40, left: 10, backgroundColor: 'white' }}>
        {stages[i]?.name ?? 'done'}
      </Text>
    </View>
  );
}

In release builds React Native ships non-image assets as res/raw resources
referenced by a bare name, which Mapbox can't load as a model. Copy them to
a cache file with a glb/gltf extension for LocationPuck and Models.

Fixes #4433
@mfazekas
mfazekas force-pushed the fix/android-glb-require-release branch from 11671cf to 55bbdbb Compare November 4, 2026 13:28
@mfazekas
mfazekas merged commit 94f4ee4 into main Nov 5, 2026
28 of 30 checks passed
@mfazekas
mfazekas deleted the fix/android-glb-require-release branch November 5, 2026 22:30

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: require()'d 3D models (.glb) fail to load on Android Release builds

1 participant