r/reactnative • u/Silent-Impress-6347 • 1h ago
Live object detection in a React Native camera with VisionCamera, TFLite and Skia, plus an AGP 9 bug that silently broke it on Android
I ship a bar inventory app (BarScan) built on Expo 58 and React Native 0.88. The camera screen finds a bottle in the live preview and draws a box around it. Some notes, in case they save someone a week.
**The pipeline**
- `react-native-vision-camera` for frames, with the resizer plugin to shrink each frame to the model's input size.
- `react-native-fast-tflite` runs a small YOLO model in a frame processor worklet.
- `@shopify/react-native-skia` draws the box and the aim line on top of the preview.
- Nothing leaves the phone at this stage. The photo is uploaded only when the user taps the shutter.
**The Android bug**
After moving to AGP 9, Android showed the camera but no boxes. No crash, no log line, nothing in Sentry. iOS was fine.
The cause: the resizer plugin (5.2.4) ships a Vulkan compute shader and relied on AGP's built-in shader build step. AGP 9 turns that step off by default. The APK was built without `assets/shaders/Resizer.comp.spv`, the resizer went into an error state, and every frame was dropped quietly.
How to check: unzip your APK and look for `assets/shaders/Resizer.comp.spv`. If it's missing, that's your bug. Upstream fixed it in 5.2.5. I backported that with a patch until I could upgrade, and added a test that fails the build if the shader file is missing.
General lesson: after any AGP or native dependency bump, check that native libraries still package their generated assets. And log the error state of every frame processor plugin. A dropped frame should not be silent.
**Offline first**
Bar cellars have no signal, so the phone can't depend on the server.
- Inventory is cached in SQLite on the device.
- Every scan and adjustment goes into an outbox and syncs later.
- The server keeps an event log as the source of truth. Stock levels are computed from the log.
- Quantities are stored as integers in base units (ml, grams, each). Display units never reach storage. This removed a whole class of rounding bugs.
Happy to go deeper on any of these. If you run YOLO in a frame processor too, what frame rate do you get on mid-range Android?