mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.25k stars 1.06k forks source link

🐛`CodeScanner` doesn't detect any Barcodes on Mi6 #1976

Closed wublack closed 10 months ago

wublack commented 11 months ago

What's happening?

I wanted to scan qrcode by the lib,but it did not work.on Mi6 Android 9 MIUI11.0.5.The same code run vivo phone(android 13) is ok!

Reproduceable Code

const codeScanner = useCodeScanner({
        codeTypes: ['qr'],
        onCodeScanned: (codes) => {
            if (codes.length > 0) {
                console.log(`${codes[0].value} `)

            } else {
                console.log('codes', codes)
            }

        }
    })
const { hasPermission, requestPermission } = useCameraPermission()
    const device = useCameraDevice('back', {
        physicalDevices: [
            'ultra-wide-angle-camera',
            'wide-angle-camera',
            'telephoto-camera'
        ]
    })
    device.formats = undefined
    console.log(JSON.stringify(device,null,2))
    const isFocused = useIsFocused();const { hasPermission, requestPermission } = useCameraPermission()
    const device = useCameraDevice('back', {
        physicalDevices: [
            'ultra-wide-angle-camera',
            'wide-angle-camera',
            'telephoto-camera'
        ]
    })
    device.formats = undefined
    console.log(JSON.stringify(device,null,2))
    const isFocused = useIsFocused();const { hasPermission, requestPermission } = useCameraPermission()
    const device = useCameraDevice('back', {
        physicalDevices: [
            'ultra-wide-angle-camera',
            'wide-angle-camera',
            'telephoto-camera'
        ]
    })
    device.formats = undefined
    console.log(JSON.stringify(device,null,2))
    const isFocused = useIsFocused();
return(
<Camera  {...props} isActive={isFocused} device={device} codeScanner={codeScanner}></Camera>
)

Relevant log output

2023-10-11 15:21:58.401 10801-13716/com.* I/CameraSession: Camera became un-available: 0
2023-10-11 15:21:58.401 10801-13716/com.* I/CameraSession: Camera became available: 1
2023-10-11 15:21:58.401 10801-10801/com.* I/CameraView: Props changed: [cameraId, isActive, codeScannerOptions]
2023-10-11 15:21:58.409 10801-10801/com.* I/PreviewView: Using Preview Size 1920 x 1080.
2023-10-11 15:21:58.410 10801-10801/com.* D/PreviewView: onMeasure(0, 0)
2023-10-11 15:21:58.410 10801-10801/com.* D/PreviewView: coverSize :: 1920x1080 (0.5625), 0x0 (NaN)
2023-10-11 15:21:58.410 10801-10801/com.* D/PreviewView: Fitted dimensions set: 0x0
2023-10-11 15:21:58.410 10801-10801/com.* I/CameraView: Configuring Camera Device...
2023-10-11 15:21:58.411 10801-10801/com.* I/CameraSession: Setting Format (fps: null | videoStabilization: null | hdr: null | lowLightBoost: null)...
2023-10-11 15:21:58.413 10801-10801/com.* I/CameraSession: Setting isActive: false (isRunning: false)
2023-10-11 15:21:58.414 10801-10801/com.* I/CameraSession: Setting isActive: true (isRunning: false)
2023-10-11 15:21:58.416 10801-10801/com.* D/PreviewView: onMeasure(1080, 1848)
2023-10-11 15:21:58.416 10801-10801/com.* D/PreviewView: coverSize :: 1920x1080 (0.5625), 1080x1848 (0.5844155844155844)
2023-10-11 15:21:58.416 10801-10801/com.* D/PreviewView: Fitted dimensions set: 1080x1920
2023-10-11 15:21:58.439 10801-10801/com.* I/PreviewView: Surface created! Surface(name=null)/@0x7341aeb
2023-10-11 15:21:58.439 10801-10801/com.* I/CameraView: Configuring Camera Device...
2023-10-11 15:21:58.440 10801-10801/com.* I/CameraSession: Configuring Session for Camera 0...
2023-10-11 15:21:58.446 10801-10801/com.* I/CameraOutputs: Preparing Outputs for Camera 0...
2023-10-11 15:21:58.446 10801-10801/com.* I/CameraOutputs: Adding native preview view output.
2023-10-11 15:21:58.448 10801-10801/com.* I/CameraOutputs: Adding 1280x720 code scanner output. (Code Types: [256])
2023-10-11 15:21:58.448 10801-10801/com.* I/CameraOutputs: Prepared 2 Outputs for Camera 0!
2023-10-11 15:21:58.448 10801-10801/com.* I/PreviewView: Surface resized! Surface(name=null)/@0x7341aeb (1920 x 1080 in format #4)
2023-10-11 15:21:58.448 10801-13716/com.* I/CameraSession: Starting Camera Session...
2023-10-11 15:21:58.449 10801-13716/com.* I/CameraManager: Camera 0: Opening...
2023-10-11 15:21:58.462 10801-13716/com.* E/libc: Access denied finding property "persist.vendor.camera.privapp.list"
2023-10-11 15:21:58.452 10801-10801/com.* W/sionCamera.main: type=1400 audit(0.0:154823): avc: denied { read } for name="u:object_r:vendor_camera_prop:s0" dev="tmpfs" ino=16960 scontext=u:r:untrusted_app:s0:c24,c259,c512,c768 tcontext=u:object_r:vendor_camera_prop:s0 tclass=file permissive=0
2023-10-11 15:21:58.462 10801-13716/com.* I/CameraManager: Using legacy camera HAL.
2023-10-11 15:21:58.467 10801-15334/com.* E/libc: Access denied finding property "vendor.camera.hal1.packagelist"
2023-10-11 15:21:58.452 10801-10801/com.* W/Thread-1087: type=1400 audit(0.0:154824): avc: denied { read } for name="u:object_r:camera_prop:s0" dev="tmpfs" ino=16851 scontext=u:r:untrusted_app:s0:c24,c259,c512,c768 tcontext=u:object_r:camera_prop:s0 tclass=file permissive=0
2023-10-11 15:21:58.470 10801-15166/com.* E/Camera: Error 2
2023-10-11 15:21:58.470 10801-15166/com.* I/RequestThread-0: Flushing all pending requests.
2023-10-11 15:21:58.470 10801-15166/com.* E/RequestQueue: cancel failed: no repeating request exists.
2023-10-11 15:21:58.470 10801-15166/com.* I/CameraDeviceState: Legacy camera service transitioning to state ERROR
2023-10-11 15:21:58.602 10801-10861/com.* I/ReactNativeJS: 'result', true
2023-10-11 15:21:58.656 10801-12667/com.* E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2023-10-11 15:21:58.661 10801-12667/com.* E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2023-10-11 15:21:58.661 10801-10862/com.* I/CameraDevices: Camera #0: Available!
2023-10-11 15:21:58.663 10801-12667/com.* E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2023-10-11 15:21:58.664 10801-12667/com.* E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2023-10-11 15:21:58.664 10801-10862/com.* I/CameraDevices: Camera #0: Unavailable!
2023-10-11 15:21:58.701 10801-13716/com.* E/libc: Access denied finding property "vendor.camera.aux.packagelist"
2023-10-11 15:21:58.711 10801-13716/com.* I/CameraManager: Camera 0: Disconnected!
2023-10-11 15:21:58.711 10801-13716/com.* D/CameraSession: Camera Closed (android.hardware.camera2.impl.CameraDeviceImpl@e37e251 == android.hardware.camera2.impl.CameraDeviceImpl@e37e251)
2023-10-11 15:21:58.711 10801-13716/com.* E/CameraView: invokeOnError(...):
2023-10-11 15:21:58.712 10801-13716/com.* W/System.err: com.mrousavy.camera.CameraDisconnectedError: [session/camera-has-been-disconnected] The given Camera device (id: 0) has been disconnected! Error: DISCONNECTED
2023-10-11 15:21:58.712 10801-13716/com.* W/System.err:     at com.mrousavy.camera.extensions.CameraManager_openCameraKt$openCamera$2$callback$1.onDisconnected(CameraManager+openCamera.kt:38)
2023-10-11 15:21:58.712 10801-13716/com.* W/System.err:     at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:245)
2023-10-11 15:21:58.712 10801-13716/com.* W/System.err:     at android.os.Handler.handleCallback(Handler.java:873)
2023-10-11 15:21:58.712 10801-13716/com.* W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
2023-10-11 15:21:58.712 10801-13716/com.* W/System.err:     at android.os.Looper.loop(Looper.java:207)
2023-10-11 15:21:58.712 10801-13716/com.* W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:65)
2023-10-11 15:21:58.720 10801-13716/com.* I/CameraSession: Camera became available: 0
2023-10-11 15:21:58.720 10801-13716/com.* I/chatty: uid=10792(com.*) sionCamera.main identical 3 lines
2023-10-11 15:21:58.720 10801-13716/com.* I/CameraSession: Camera became available: 0
2023-10-11 15:21:58.720 10801-13716/com.* I/CameraSession: Camera became un-available: 0
2023-10-11 15:21:58.720 10801-13716/com.* I/chatty: uid=10792(com.*) sionCamera.main identical 3 lines
2023-10-11 15:21:58.720 10801-13716/com.* I/CameraSession: Camera became un-available: 0
2023-10-11 15:21:58.720 10801-13716/com.* I/CameraManager: Camera 0: Opened!
2023-10-11 15:21:58.727 10801-13716/com.* I/CreateCaptureSession: Camera 0: Creating Capture Session #1004... Hardware Level: 2} | Outputs: [PREVIEW (1920 x 1080), VIDEO (1280 x 720 1 BarcodeScanner)]
2023-10-11 15:21:58.728 10801-13716/com.* I/CreateCaptureSession: Using new API (>=28)
2023-10-11 15:21:58.729 10801-13716/com.* I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
2023-10-11 15:21:58.730 10801-15382/com.* I/RequestThread-0: Configure outputs: 2 surfaces configured.
2023-10-11 15:21:58.730 10801-15382/com.* D/Camera: app passed NULL surface
2023-10-11 15:21:58.742 10801-15384/com.* E/libc: Access denied finding property "persist.camera.legacy_perf"
2023-10-11 15:21:58.760 10801-13716/com.* I/CameraDeviceState: Legacy camera service transitioning to state IDLE
2023-10-11 15:21:58.761 10801-13716/com.* I/CreateCaptureSession: Camera 0: Capture Session #1003 closed!
2023-10-11 15:21:58.761 10801-13716/com.* D/CameraSession: Capture Session Closed (android.hardware.camera2.impl.CameraCaptureSessionImpl@47a724 == android.hardware.camera2.impl.CameraCaptureSessionImpl@47a724)
2023-10-11 15:21:58.761 10801-13716/com.* I/CreateCaptureSession: Camera 0: Capture Session #1004 configured!
2023-10-11 15:21:58.762 10801-13716/com.* I/CameraView: invokeOnInitialized()
2023-10-11 15:21:58.763 10801-13716/com.* I/CameraSession: Adding preview output surface PREVIEW..
2023-10-11 15:21:58.763 10801-13716/com.* I/CameraSession: Adding code scanner output surface VIDEO
2023-10-11 15:21:58.763 10801-13716/com.* I/CameraSession: Camera Session initialized! Starting repeating request..
2023-10-11 15:21:58.771 10801-13716/com.* D/CameraSession: Setting Repeating Request..
2023-10-11 15:21:58.771 10801-13716/com.* I/RequestQueue: Repeating capture request set.
2023-10-11 15:21:58.778 10801-15382/com.* W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
2023-10-11 15:21:58.779 10801-15382/com.* W/LegacyRequestMapper: Only received metering rectangles with weight 0.
2023-10-11 15:21:58.779 10801-15382/com.* W/LegacyRequestMapper: Only received metering rectangles with weight 0.
2023-10-11 15:21:59.062 10801-15384/com.* I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
2023-10-11 15:22:04.014 10801-10801/com.* I/PreviewView: Surface destroyed! Surface(name=null)/@0x7341aeb
2023-10-11 15:22:04.014 10801-10801/com.* I/CameraView: Configuring Camera Device...
2023-10-11 15:22:04.016 10801-10801/com.* I/CameraSession: Setting isActive: true (isRunning: true)

Camera Device

{
  "sensorOrientation": "landscape-right",
  "hardwareLevel": "legacy",
  "maxZoom": 10,
  "minZoom": 1,
  "supportsLowLightBoost": false,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "supportsFocus": true,
  "supportsRawCapture": false,
  "isMultiCam": false,
  "name": "BACK (0)",
  "hasFlash": true,
  "hasTorch": true,
  "position": "back",
  "id": "0"
}

Device

Mi6

VisionCamera Version

3.3.1

Can you reproduce this issue in the VisionCamera Example app?

No, I cannot reproduce the issue in the Example app

Additional information

zzz08900 commented 11 months ago

Well I guess there's your problem 'The given Camera device (id: 0) has been disconnected'

You only got one camera so try just use that one.

wublack commented 11 months ago

Well I guess there's your problem 'The given Camera device (id: 0) has been disconnected'

You only got one camera so try just use that one.

NO!I don't think so! When i use this API " useCameraDevices().length" get camera devices ,return two

mrousavy commented 11 months ago

Did you Setup the CodeScanner properly? It needs google play services to download the MLKit model.

mrousavy commented 11 months ago

Try changing this line in node_modules/react-native-vision-camera/android/build.gradle:

https://github.com/mrousavy/react-native-vision-camera/blob/18e69269d49f38de11693cbec61ee9e280a1f6e9/package/android/build.gradle#L147

to

implementation 'com.google.mlkit:barcode-scanning:17.2.0'

then rebuild your app and see if that works then.

zzz08900 commented 11 months ago

To anyone who has no idea what @mrousavy is suggesting:

Did you Setup the CodeScanner properly? It needs google play services to download the MLKit model.

I think by default Mi6 does not have Google Play services installed/enabled so the it needs to an apk with preloaded models otherwise MLKit won't work.

wublack commented 11 months ago

Did you Setup the CodeScanner properly? It needs google play services to download the MLKit model.

Thanks! I have configured!It don't work!

wublack commented 11 months ago

To anyone who has no idea what @mrousavy is suggesting:

Did you Setup the CodeScanner properly? It needs google play services to download the MLKit model.

I think by default Mi6 does not have Google Play services installed/enabled so the it needs to an apk with preloaded models otherwise MLKit won't work.

only Mi6 has this problem,other phone is work(vivo phone).when i using the old lib react-native-camera ,Mi6 is ok ,

mrousavy commented 10 months ago

They're doing nothing really different than I am as far as I can tell - I#m just using a newer version of the library. https://github.com/react-native-camera/react-native-camera/blob/master/android/src/mlkit/java/org/reactnative/barcodedetector/RNBarcodeDetector.java

@wublack are you 100% sure that you changed the line in the build.gradle file, synced your project (gradle sync in Android Studio), and then rebuilt the app and it still didn't work?

wublack commented 10 months ago

I am pretty sure ! I remove the "node_module" folder ,try again it's didn't work! If the build.gradle file is not config, error listener will also prompt, right! But there is no prompt in the log.@mrousavy 微信图片_20231016102355

mrousavy commented 10 months ago

So I guess MLKit just doesn't work on that phone then? I don't know, doesn't seem like there's anything I can do here.

I could use ZXing instead of MLKit on Android, but I heard that's slower.

@wublack you can try to build a native Java Android app and try if MLKit works on that phone by following this guide.

wublack commented 10 months ago

So I guess MLKit just doesn't work on that phone then? I don't know, doesn't seem like there's anything I can do here.

I could use ZXing instead of MLKit on Android, but I heard that's slower.

@wublack you can try to build a native Java Android app and try if MLKit works on that phone by following this guide.

Thanks! I try it,but it's worked on Mi6 ,using camerax+mlkit ,I feel very frustrated !

wublack commented 10 months ago

Thanks! It's my code bug ! const isFocused = useIsFocused(); the Bugs will appear when i using constant isFocused. The components has not refresh! But I don't know why ios phone and other android phone refresh component when i using constant isFocused.

mrousavy commented 10 months ago

🙃

hengkx commented 10 months ago

Try changing this line in node_modules/react-native-vision-camera/android/build.gradle:

https://github.com/mrousavy/react-native-vision-camera/blob/18e69269d49f38de11693cbec61ee9e280a1f6e9/package/android/build.gradle#L147

to

implementation 'com.google.mlkit:barcode-scanning:17.2.0'

then rebuild your app and see if that works then.

Thank you very much. The QR code can be recognized, but the screen will appear black when back