[Bug]: Android 17: scanner closes with OS-PLUG-BARC-0004 because CameraX 1.5.1 throws on unknown dynamic range profile 8192

Aperta
#147 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android
Ambito
mobile

Direzione di ricerca

Start with the CameraX version declared in android/build.gradle and the OSBARCScannerActivity error path that maps the failure to OS-PLUG-BARC-0004. Check whether ionbarcode-android pins its own CameraX version, since the fix may need to land there too. Reproduce on an Android 17 emulator with the back camera, then confirm the scanner stays open after bumping CameraX to 1.6.x and that Android 16 still works.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Current Behavior

On Android 17 (API 37), scanBarcode() opens the scanner activity, which closes again after about 1 second, and the promise rejects with:

{"message":"Error while trying to scan code.","code":"OS-PLUG-BARC-0004"}

Logcat at that moment:

E OSBARCScannerActivity: Dynamic range profile cannot be converted to a DynamicRange object: 8192

The back camera on Android 17 advertises dynamic range profiles that CameraX 1.5.1 doesn't know (8192 and 16384 in android.request.availableDynamicRangeProfilesMap). In CameraX 1.5.1, DynamicRangesCompatApi33Impl.profileToDynamicRange() wraps the conversion in Preconditions.checkNotNull(...). An unknown profile therefore throws while the camera is being bound, and ionbarcode-android reports that as the generic SCANNING_GENERAL_ERROR (0004).

Starting with CameraX 1.6, the same conversion (DynamicRangeProfilesCompatApi33Impl.profileToDynamicRange()) only logs a warning and skips the unknown profile. I checked the sources of 1.5.1, 1.6.2 and 1.7.0-rc01.

Expected Behavior

The scanner opens and stays open on Android 17, as it does on Android 16.

Reproduction
  1. Use any app with @capacitor/barcode-scanner 3.1.3 (which pulls CameraX 1.5.1) and call CapacitorBarcodeScanner.scanBarcode({ hint: CapacitorBarcodeScannerTypeHint.ALL }).
  2. Run it on the Android Emulator with the Android 17 (API 37.1) Google Play system image and -camera-back emulated.
  3. The scanner closes immediately and the call rejects with OS-PLUG-BARC-0004. The same APK works on an API 36 emulator.

adb shell dumpsys media.camera shows the back camera advertising profile 8192. The front camera doesn't, which is why it only fails with the back camera.

Environment Details
  • @capacitor/barcode-scanner 3.1.3 (3.1.4-dev-20261007T140411.0 still declares CameraX 1.5.1)
  • io.ionic.libs:ionbarcode-android 2.1.1
  • androidx.camera:* 1.5.1, resolved through the plugin
  • @capacitor/core / @capacitor/android 8.6
  • compileSdk / targetSdk 36, AGP 8.13
Versions Affected

3.1.3, and the current 3.1.4 dev build

Platforms Affected
  • iOS
  • Android
  • Web
Notes / Comments

Workaround that fixed it for us: force CameraX 1.6.2 from the app module (android/app/build.gradle):

dependencies {
    constraints {
        ['camera-core', 'camera-camera2', 'camera-lifecycle', 'camera-view'].each { module ->
            implementation("androidx.camera:${module}:1.6.2") {
                because 'CameraX 1.5 throws on dynamic range profiles added in Android 17'
            }
        }
    }
}

With that change, the release build (R8 enabled) opens the scanner on Android 17, and logcat shows the message only as a warning (W CXCP: Dynamic range profile cannot be converted to a DynamicRange object: 8192 / 16384). Android 16 keeps working. CameraX 1.6.2 requires compileSdk 36 and AGP 8.9.1 or newer.

Suggested fix: bump the CameraX dependencies in android/build.gradle (and in ionbarcode-android, if it pins them) to 1.6.x.

So far we've only seen this on the emulator. Real Android 17 devices may advertise different profiles, but any camera that advertises a profile newer than CameraX 1.5.1 will hit the same exception.

#141 looks related: CameraX rejects a value it doesn't recognize (lens facing 255 there), and the user also only sees the generic OS-PLUG-BARC-0004. It might help to forward the underlying exception message in the rejection, so these cases can be diagnosed without logcat.

Lingua principale
TypeScript
Stelle
65
Fork
47
Merge medio
2g 15h
PR unite (30g)
6

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/capacitor-barcode-scanner

Tutte le issue di ionic-team/capacitor-barcode-scanner

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.