natario1 / CameraView

📸 A well documented, high-level Android interface that makes capturing pictures and videos easy, addressing all of the common issues and needs. Real-time filters, gestures, watermarks, frame processing, RAW, output of any size.
https://natario1.github.io/CameraView
Other
4.96k stars 938 forks source link

Camera1 crash on API30 #935

Closed Asshes closed 4 years ago

Asshes commented 4 years ago

Currently we are testing Android 11 Beta version [API 30]

Describe the bug

To Reproduce

Steps to reproduce the behavior, possibly in the demo app:

  1. Open Application
  2. Press capture
  3. See error

Expected behavior

Expected that WHEN I click to take photo with back camera THEN app won't crash Taking photo with back camera does not bring to image view just stays at photo taking screen & pressing to take photo couple more times just crashes app

XML layout

<com.otaliastudios.cameraview.CameraView xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/camera" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:keepScreenOn="true" app:cameraAudio="on" app:cameraCropOutput="false" app:cameraFacing="back" app:cameraFlash="auto" app:cameraGestureLongTap="none" app:cameraGesturePinch="zoom" app:cameraGestureScrollHorizontal="exposureCorrection" app:cameraGestureScrollVertical="zoom" app:cameraGestureTap="focusWithMarker" app:cameraGrid="off" app:cameraJpegQuality="100" app:cameraPlaySounds="true" app:cameraSessionType="picture" />

Screenshots

No screenshots - it's just crash on taking photo action.

Logs

With Demo application

2020-08-07 20:28:11.864 6336-6363/com.otaliastudios.cameraview.demo E/CameraEngine: CameraDevice.StateCallback reported an error: 4 2020-08-07 20:28:44.708 6336-6363/com.otaliastudios.cameraview.demo E/AndroidRuntime: FATAL EXCEPTION: CameraViewEngine Process: com.otaliastudios.cameraview.demo, PID: 6336 com.otaliastudios.cameraview.CameraException at com.otaliastudios.cameraview.engine.Camera2Engine$2.onError(Camera2Engine.java:453) at android.hardware.camera2.impl.CameraDeviceImpl.notifyError(CameraDeviceImpl.java:1629) at android.hardware.camera2.impl.CameraDeviceImpl.lambda$oDs27OTfKFfK18rUW2nQxxkPdV0(Unknown Source:0) at android.hardware.camera2.impl.-$$Lambda$CameraDeviceImpl$oDs27OTfKFfK18rUW2nQxxkPdV0.accept(Unknown Source:8) at com.android.internal.util.function.pooled.PooledLambdaImpl.doInvoke(PooledLambdaImpl.java:278) at com.android.internal.util.function.pooled.PooledLambdaImpl.invoke(PooledLambdaImpl.java:201) at com.android.internal.util.function.pooled.OmniFunction.run(OmniFunction.java:97) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.os.HandlerThread.run(HandlerThread.java:67)


2020-08-07 20:32:23.419 6681-6681/? I/cameraview.dem: Not late-enabling -Xcheck:jni (already on) 2020-08-07 20:32:23.433 6681-6681/? I/cameraview.dem: Unquickening 12 vdex files! 2020-08-07 20:32:23.434 6681-6681/? W/cameraview.dem: Unexpected CPU variant for X86 using defaults: x86 2020-08-07 20:32:23.714 6681-6681/com.otaliastudios.cameraview.demo W/ActivityThread: Application com.otaliastudios.cameraview.demo is waiting for the debugger on port 8100... 2020-08-07 20:32:23.731 6681-6681/com.otaliastudios.cameraview.demo I/System.out: Sending WAIT chunk 2020-08-07 20:32:24.536 6681-6681/com.otaliastudios.cameraview.demo I/System.out: Debugger has connected 2020-08-07 20:32:24.536 6681-6681/com.otaliastudios.cameraview.demo I/System.out: waiting for debugger to settle... 2020-08-07 20:32:24.961 6681-6681/com.otaliastudios.cameraview.demo I/chatty: uid=10151(com.otaliastudios.cameraview.demo) identical 2 lines 2020-08-07 20:32:25.162 6681-6681/com.otaliastudios.cameraview.demo I/System.out: waiting for debugger to settle... 2020-08-07 20:32:25.364 6681-6681/com.otaliastudios.cameraview.demo I/System.out: waiting for debugger to settle... 2020-08-07 20:32:25.566 6681-6681/com.otaliastudios.cameraview.demo I/chatty: uid=10151(com.otaliastudios.cameraview.demo) identical 1 line 2020-08-07 20:32:25.768 6681-6681/com.otaliastudios.cameraview.demo I/System.out: waiting for debugger to settle... 2020-08-07 20:32:25.970 6681-6681/com.otaliastudios.cameraview.demo I/System.out: debugger has settled (1443) 2020-08-07 20:32:25.976 6681-6681/com.otaliastudios.cameraview.demo D/ApplicationLoaders: Returning zygote-cached class loader: /system/framework/android.test.base.jar 2020-08-07 20:32:26.101 6681-6681/com.otaliastudios.cameraview.demo D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2020-08-07 20:32:26.107 6681-6681/com.otaliastudios.cameraview.demo D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2020-08-07 20:32:26.154 6681-6729/com.otaliastudios.cameraview.demo D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so 2020-08-07 20:32:26.167 6681-6729/com.otaliastudios.cameraview.demo D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so 2020-08-07 20:32:26.170 6681-6729/com.otaliastudios.cameraview.demo D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so 2020-08-07 20:32:26.272 6681-6681/com.otaliastudios.cameraview.demo W/System.err: java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system) 2020-08-07 20:32:26.273 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at libcore.io.IoBridge.open(IoBridge.java:492) 2020-08-07 20:32:26.274 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at java.io.FileOutputStream.(FileOutputStream.java:236) 2020-08-07 20:32:26.275 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at org.jacoco.agent.rt.internal_8ff85ea.output.FileOutput.openFile(FileOutput.java:67) 2020-08-07 20:32:26.276 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at org.jacoco.agent.rt.internal_8ff85ea.output.FileOutput.startup(FileOutput.java:49) 2020-08-07 20:32:26.277 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at org.jacoco.agent.rt.internal_8ff85ea.Agent.startup(Agent.java:122) 2020-08-07 20:32:26.279 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at org.jacoco.agent.rt.internal_8ff85ea.Agent.getInstance(Agent.java:50) 2020-08-07 20:32:26.280 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at org.jacoco.agent.rt.internal_8ff85ea.Offline.(Offline.java:31) 2020-08-07 20:32:26.281 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at org.jacoco.agent.rt.internal_8ff85ea.Offline.getProbes(Offline.java:51) 2020-08-07 20:32:26.282 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at com.otaliastudios.cameraview.CameraLogger.$jacocoInit(Unknown Source:13) 2020-08-07 20:32:26.282 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at com.otaliastudios.cameraview.CameraLogger.(Unknown Source:0) 2020-08-07 20:32:26.284 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at com.otaliastudios.cameraview.CameraLogger.create(Unknown Source:0) 2020-08-07 20:32:26.285 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at com.otaliastudios.cameraview.demo.CameraActivity.(CameraActivity.java:49) 2020-08-07 20:32:26.285 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at java.lang.Class.newInstance(Native Method) 2020-08-07 20:32:26.287 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95) 2020-08-07 20:32:26.288 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41) 2020-08-07 20:32:26.289 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.Instrumentation.newActivity(Instrumentation.java:1253) 2020-08-07 20:32:26.290 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353) 2020-08-07 20:32:26.291 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 2020-08-07 20:32:26.292 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 2020-08-07 20:32:26.293 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 2020-08-07 20:32:26.295 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 2020-08-07 20:32:26.296 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 2020-08-07 20:32:26.296 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.os.Handler.dispatchMessage(Handler.java:106) 2020-08-07 20:32:26.297 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.os.Looper.loop(Looper.java:223) 2020-08-07 20:32:26.298 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7656) 2020-08-07 20:32:26.299 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at java.lang.reflect.Method.invoke(Native Method) 2020-08-07 20:32:26.300 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 2020-08-07 20:32:26.301 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 2020-08-07 20:32:26.304 6681-6681/com.otaliastudios.cameraview.demo W/System.err: Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system) 2020-08-07 20:32:26.305 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at libcore.io.Linux.open(Native Method) 2020-08-07 20:32:26.306 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:166) 2020-08-07 20:32:26.307 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254) 2020-08-07 20:32:26.308 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at libcore.io.ForwardingOs.open(ForwardingOs.java:166) 2020-08-07 20:32:26.309 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7542) 2020-08-07 20:32:26.310 6681-6681/com.otaliastudios.cameraview.demo W/System.err: at libcore.io.IoBridge.open(IoBridge.java:478) 2020-08-07 20:32:26.311 6681-6681/com.otaliastudios.cameraview.demo W/System.err: ... 27 more 2020-08-07 20:32:26.577 6681-6681/com.otaliastudios.cameraview.demo W/cameraview.dem: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 2020-08-07 20:32:26.577 6681-6681/com.otaliastudios.cameraview.demo W/cameraview.dem: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 2020-08-07 20:32:27.767 6681-6681/com.otaliastudios.cameraview.demo W/cameraview.dem: Accessing hidden method Landroid/graphics/FontFamily;->()V (greylist-max-q, reflection, allowed) 2020-08-07 20:32:27.767 6681-6681/com.otaliastudios.cameraview.demo W/cameraview.dem: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (greylist-max-q, reflection, allowed) 2020-08-07 20:32:27.768 6681-6681/com.otaliastudios.cameraview.demo W/cameraview.dem: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (greylist-max-q, reflection, allowed) 2020-08-07 20:32:27.768 6681-6681/com.otaliastudios.cameraview.demo W/cameraview.dem: Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (greylist-max-q, reflection, allowed) 2020-08-07 20:32:27.768 6681-6681/com.otaliastudios.cameraview.demo W/cameraview.dem: Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (greylist-max-q, reflection, allowed) 2020-08-07 20:32:27.768 6681-6681/com.otaliastudios.cameraview.demo W/cameraview.dem: Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (greylist, reflection, allowed) 2020-08-07 20:32:27.933 6681-6681/com.otaliastudios.cameraview.demo I/CameraOrchestrator: HAS FRAME PROCESSORS (TRUE) - Scheduling. 2020-08-07 20:32:27.936 6681-6730/com.otaliastudios.cameraview.demo I/CameraOrchestrator: HAS FRAME PROCESSORS (TRUE) - Executing. 2020-08-07 20:32:27.938 6681-6730/com.otaliastudios.cameraview.demo I/CameraOrchestrator: HAS FRAME PROCESSORS (TRUE) - Finished. 2020-08-07 20:32:29.219 6681-6681/com.otaliastudios.cameraview.demo I/Angles: Angles changed: sensorOffset: 0 displayOffset: 0 deviceOrientation: 0 2020-08-07 20:32:29.220 6681-6681/com.otaliastudios.cameraview.demo I/CameraEngine: START: scheduled. State: OFF 2020-08-07 20:32:29.223 6681-6681/com.otaliastudios.cameraview.demo I/CameraOrchestrator: OFF >> ENGINE - Scheduling. 2020-08-07 20:32:29.225 6681-6730/com.otaliastudios.cameraview.demo I/CameraOrchestrator: OFF >> ENGINE - Executing. 2020-08-07 20:32:29.225 6681-6730/com.otaliastudios.cameraview.demo I/CameraManagerGlobal: Connecting to camera service 2020-08-07 20:32:29.230 6681-6681/com.otaliastudios.cameraview.demo I/CameraOrchestrator: ENGINE >> BIND - Scheduling. 2020-08-07 20:32:29.233 6681-6681/com.otaliastudios.cameraview.demo I/CameraOrchestrator: BIND >> PREVIEW - Scheduling. 2020-08-07 20:32:29.233 6681-6730/com.otaliastudios.cameraview.demo I/CameraEngine: collectCameraInfo Facing: BACK Internal: 1 Cameras: 2 2020-08-07 20:32:29.240 6681-6730/com.otaliastudios.cameraview.demo I/Angles: Angles changed: sensorOffset: 90 displayOffset: 0 deviceOrientation: 0 2020-08-07 20:32:29.271 6681-6730/com.otaliastudios.cameraview.demo I/CameraEngine: onStartEngine: Opened camera device. 2020-08-07 20:32:29.358 6681-6730/com.otaliastudios.cameraview.demo I/CameraEngine: applyAllParameters: called for tag 1 2020-08-07 20:32:29.370 6681-6730/com.otaliastudios.cameraview.demo I/CameraOrchestrator: OFF >> ENGINE - Finished. 2020-08-07 20:32:29.373 6681-6730/com.otaliastudios.cameraview.demo I/CameraOrchestrator: ENGINE >> BIND - Executing. 2020-08-07 20:32:29.375 6681-6730/com.otaliastudios.cameraview.demo I/CameraOrchestrator: ENGINE >> BIND - Finished because ABORTED. 2020-08-07 20:32:29.379 6681-6730/com.otaliastudios.cameraview.demo I/CameraOrchestrator: BIND >> PREVIEW - Executing. 2020-08-07 20:32:29.381 6681-6730/com.otaliastudios.cameraview.demo W/CameraOrchestrator: BIND >> PREVIEW - State mismatch, aborting. current: ENGINE from: BIND to: PREVIEW 2020-08-07 20:32:29.383 6681-6730/com.otaliastudios.cameraview.demo I/CameraOrchestrator: BIND >> PREVIEW - Finished because ABORTED. 2020-08-07 20:32:29.596 6681-6681/com.otaliastudios.cameraview.demo W/CameraView: doInstantiateEngine: instantiating. preview: GL_SURFACE 2020-08-07 20:32:29.611 6681-6...


With our application Process: lt.sciil.spa, PID: 7123 com.otaliastudios.cameraview.CameraException: java.lang.RuntimeException: Error inside the onError callback. 2 at com.otaliastudios.cameraview.Camera1.onError(Camera1.java:272) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1268) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: java.lang.RuntimeException: Error inside the onError callback. 2 at com.otaliastudios.cameraview.Camera1.onError(Camera1.java:272) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1268) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.os.HandlerThread.run(HandlerThread.java:67) 2020-07-17 15:00:16.792 7123-7231/lt.sciil.spa E/CameraController: uncaughtException: Interrupting thread with state: STATE_STARTED due to CameraException: com.otaliastudios.cameraview.CameraException: java.lang.RuntimeException: Error inside the onError callback. 2 com.otaliastudios.cameraview.CameraException: java.lang.RuntimeException: Error inside the onError callback. 2 at com.otaliastudios.cameraview.Camera1.onError(Camera1.java:272) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1268) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: java.lang.RuntimeException: Error inside the onError callback. 2 at com.otaliastudios.cameraview.Camera1.onError(Camera1.java:272) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1268) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.os.HandlerThread.run(HandlerThread.java:67)

APK

We don't have github repository available for security reasons Someone could connect me personally for details: infernum.hircum@gmail.com

mobielbekeken-thijs commented 4 years ago

Same here. I think it is related to a bug in API 30: https://issuetracker.google.com/issues/158818461

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 20 days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Canato commented 4 years ago

@natario1 would this be related to Permissions that changed in Android 11?

I believe this is the same issue as #799

If is this the case, Permissions + URI external issue, I could work on the fix for the camera.

Just need to know if this library need to write any data and if need to use Scoped Storage

natario1 commented 4 years ago

The library only writes on File and FileDescriptor that you pass to it, so you just have to make sure you pass files / descriptors that you have access to. It's not something to be fixed inside

Asshes commented 4 years ago

We additionally found this, seems also related. https://commonsware.com/blog/2020/08/16/action-image-capture-android-r.html

Canato commented 4 years ago

The solution for us was change the URI from external to the authority(fileProvider) URI

val photoURI: Uri = FileProvider.getUriForFile(this, "com.example.android.fileprovider", it) based on https://developer.android.com/training/camera/photobasics#kotlin

Hope this help more people

This change was based on the new Android 11 storage permissions https://developer.android.com/about/versions/11/privacy/storage now we should not use WRITE/READ permissions but we can use a directly app storage

wataik commented 4 years ago

I'm experiencing the same error when using emulator camera with VirtualScene mode while there is no issue with Emulated mode. The issue actually occurs with the demo app.

Here's the set up details.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 20 days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.